Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ jobs:
with:
submodules: recursive
persist-credentials: false
- name: Install system libraries for lxml
run: |
sudo apt-get update
sudo apt-get install -y libxml2-dev libxslt1-dev
- name: Use Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
Expand Down Expand Up @@ -78,6 +82,10 @@ jobs:
with:
submodules: recursive
persist-credentials: false
- name: Install system libraries for lxml
run: |
sudo apt-get update
sudo apt-get install -y libxml2-dev libxslt1-dev
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405
with:
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pyld ChangeLog

## 3.0.0 - 2025-xx-xx
## 3.0.0 - 2026-04-02

### Changed
- **BREAKING**: Require supported Python version >= 3.10.
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ test:
upgrade-submodules:
git submodule update --remote --init --recursive

# TODO: Expand to lib/ and tests/ as linting issues are resolved.
RUFF_TARGET = lib/pyld/*.py tests/*.py

lint:
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ document loader is a dummy document loader that raises an exception on every
invocation.

Handling ignored properties during JSON-LD expansion
----------------------------------------------
----------------------------------------------------

If a property in a JSON-LD document does not map to an absolute IRI then it is
ignored. You can customize this behaviour by passing a customizable handler to
Expand Down
4 changes: 2 additions & 2 deletions lib/pyld/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
__all__ = ['__copyright__', '__license__', '__version__']

__copyright__ = 'Copyright (c) 2011-2024 Digital Bazaar, Inc.'
__license__ = 'New BSD license'
__version__ = '2.0.5-dev'
__license__ = 'BSD 3-Clause "New" or "Revised" License'
__version__ = '3.1.0-dev'
4 changes: 1 addition & 3 deletions lib/pyld/jsonld.py
Original file line number Diff line number Diff line change
Expand Up @@ -5842,8 +5842,7 @@ def _expand_iri(

# resolve against base
rval = value
# if there is a base in the active context, use that
if '@base' in active_ctx:
if base is not None and '@base' in active_ctx:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you preserve the comment and adjust where appropriate?

# the None case preserves rval as potentially relative
if active_ctx['@base'] is not None:
resolved_base = (
Expand All @@ -5856,7 +5855,6 @@ def _expand_iri(
# we should fallback to document base
elif base == '':
rval = resolve(rval, DEFAULT_BASE_IRI)
# in other cases, use the base that was passed to this function
elif base:
rval = resolve(rval, base)

Expand Down
33 changes: 33 additions & 0 deletions tests/test_base_vs_vocab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
Regression test: @base must not be used to expand property keys.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to have this as part of

class TestExpand:
. I have a refactor of the class-based tests to function-based tests somewhere on the todo list, but for the time being, let's follow the same structure.


Property names are expanded vocabulary-relative: @vocab, term definitions,
compact IRIs with a defined prefix, etc. The active context's @base is for
document-relative IRI resolution where the algorithms pass that flag (e.g.
certain @id and @type values), not for turning arbitrary keys into absolute
IRIs. Here the context sets only @base; `name` has no term definition and no
@vocab, so it cannot become an absolute property IRI and must be dropped.

See: https://www.w3.org/TR/json-ld11-api/#iri-expansion
"""

import pyld.jsonld as jsonld


def test_base_does_not_expand_property_terms():
"""Property keys must not be resolved against @base without vocabulary-relative mapping."""
doc = {
'@context': {'@base': 'https://schema.org/'},
'@id': 'https://w3.org/yaml-ld/',
'@type': 'WebContent',
'name': 'YAML-LD',
}
result = jsonld.expand(doc)
# `name` has no vocabulary-relative mapping (@vocab or term definition);
# @base must not supply one. The key is dropped.
assert result == [
{
'@id': 'https://w3.org/yaml-ld/',
'@type': ['https://schema.org/WebContent'],
}
]
Loading