From 03e66acc5fd19c42a62910383b2c35677a3eb3f3 Mon Sep 17 00:00:00 2001 From: Miel Vander Sande Date: Wed, 8 Jul 2026 22:36:14 +0200 Subject: [PATCH 1/2] Add blank nodes to prefix check --- CHANGELOG.md | 1 + lib/pyld/jsonld.py | 5 ++++- tests/test_jsonld.py | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b69c4d0..71049304 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - When using native types, values of `xsd:boolean` and `xsd:integer` are now properly converted. Fixes [fromRdf#t0027](https://w3c.github.io/json-ld-api/tests/fromRdf-manifest.html#t0027). - Numbers with 0 as fractional part now parse to an `xsd:integer` instead of `xsd:double`. Fixes [toRdf#ttn02](https://w3c.github.io/json-ld-api/tests/toRdf-manifest.html#ttn02). - Zeros are now truncated for numeric values with negative exponent. +- Blank node prefixes are now also used in IRI expansion. ## 3.1.0 - 2026-06-19 diff --git a/lib/pyld/jsonld.py b/lib/pyld/jsonld.py index a18f32e8..1d1e88da 100644 --- a/lib/pyld/jsonld.py +++ b/lib/pyld/jsonld.py @@ -5742,7 +5742,10 @@ def _create_term_definition( mapping['_prefix'] = ( _simple_term and not mapping['_term_has_colon'] - and bool(re.match(r'.*[:/\?#\[\]@]$', id_)) + and ( + id_.startswith('_:') + or bool(re.match(r'.*[:/\?#\[\]@]$', id_)) + ) ) if '@id' not in mapping: # see if the term has a prefix diff --git a/tests/test_jsonld.py b/tests/test_jsonld.py index d9efdc81..130797ef 100644 --- a/tests/test_jsonld.py +++ b/tests/test_jsonld.py @@ -535,6 +535,20 @@ def test_expand_stringifies_datetime_date_values(self): 'https://schema.org/publicationDate': [{'@value': '2021-01-11'}], }] + # Issue 167 + def test_blank_node_prefixes(self): + """ + Blank nodes as prefix should be used in IRI expansion. + """ + input = {"@context": {"t": "_:b"}, "@type": "t:x"} + + expected = [{"@type": ["_:bx"]}] + + expanded = jsonld.expand(input) + + assert expanded == expected + + class TestFrame: # Issue 11 - PR: https://github.com/digitalbazaar/pyld/issues/149 """ From b9013decb9840922bd06a907c455c450e462bbda Mon Sep 17 00:00:00 2001 From: Miel Vander Sande Date: Thu, 9 Jul 2026 09:21:20 +0200 Subject: [PATCH 2/2] Satisfy linter --- tests/test_jsonld.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_jsonld.py b/tests/test_jsonld.py index 130797ef..bc669a79 100644 --- a/tests/test_jsonld.py +++ b/tests/test_jsonld.py @@ -538,7 +538,7 @@ def test_expand_stringifies_datetime_date_values(self): # Issue 167 def test_blank_node_prefixes(self): """ - Blank nodes as prefix should be used in IRI expansion. + Blank nodes as prefix should be used in IRI expansion. """ input = {"@context": {"t": "_:b"}, "@type": "t:x"}