diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f6f035..0452778 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixed - When compacting, expands the index mapping first, then compacts that expanded IRI, matching the JSON-LD API compaction correction for compact-IRI index mappings. Fixes testcases [compact#t0112](https://w3c.github.io/json-ld-api/tests/compact-manifest.html#t0112) and [compact#t0113](https://w3c.github.io/json-ld-api/tests/compact-manifest.html#t0113). - Fixes `AttributeError` when compacting with `@none`: the `@type` map compaction path now only calls `.pop()` and inspects keys when `compacted_item` is actually an object. Fixes [compact#tm023](https://w3c.github.io/json-ld-api/tests/compact-manifest.html#tm023) +- An empty property-scoped context no longer resets the active context in `_create_term_definition`. Now only explicit null becomes False; empty contexts are preserved. Fixes [compact#tc028](https://w3c.github.io/json-ld-api/tests/compact-manifest.html#tc028) and [toRdf#tc036](https://w3c.github.io/json-ld-api/tests/toRdf-manifest.html#tc036). ### Added - `pyld.DocumentLoader` abstract base class for class-based document loaders, diff --git a/lib/pyld/jsonld.py b/lib/pyld/jsonld.py index acca64d..f715fe0 100644 --- a/lib/pyld/jsonld.py +++ b/lib/pyld/jsonld.py @@ -5709,8 +5709,10 @@ def _create_term_definition( # scoped contexts if '@context' in value: - # record as falss, if None - mapping['@context'] = value['@context'] if value['@context'] else False + # record as false, if None + mapping['@context'] = ( + False if value['@context'] is None else value['@context'] + ) if '@language' in value and '@type' not in value: language = value['@language'] diff --git a/tests/runtests.py b/tests/runtests.py index 3e5b71f..a8a72ab 100644 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -904,10 +904,7 @@ def write(self, filename): # skip tests where behavior changed for a 1.1 processor # see JSON-LD 1.0 Errata 'specVersion': ['json-ld-1.0'], - 'idRegex': [ - # uncategorized - '.*compact-manifest#tc028$', - ], + 'idRegex': [], }, 'fn': 'compact', 'params': [ @@ -1033,7 +1030,6 @@ def write(self, filename): '.*toRdf-manifest#ter56$', '.*toRdf-manifest#tli12$', '.*toRdf-manifest#tli14$', - '.*toRdf-manifest#tc036$', '.*toRdf-manifest#tc037$', ] }, diff --git a/tests/test_jsonld.py b/tests/test_jsonld.py index d1fd80e..6f9699d 100644 --- a/tests/test_jsonld.py +++ b/tests/test_jsonld.py @@ -892,6 +892,37 @@ def test_node_reference_compacts_to_string_value_of_type_map(self): "location": {"@none": "http://kg.artsdata.ca/resource/K11-200"}, } + def test_empty_property_scoped_context_preserves_outer_terms(self): + """ + An empty property-scoped context should not reset the active context + during compaction. + """ + expanded = [ + { + "http://example.com/title": [{"@value": "top"}], + "http://example.com/thing": [ + { + "http://example.com/title": [{"@value": "sub"}], + } + ], + } + ] + context = { + "@context": { + "ex": "http://example.com/", + "thing": {"@id": "ex:thing", "@context": {}}, + "title": "ex:title", + } + } + + compacted = jsonld.compact(expanded, context, {"skipExpansion": True}) + + assert compacted == { + "@context": context["@context"], + "title": "top", + "thing": {"title": "sub"}, + } + # Issue 91 def test_empty_context(self): """