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..bc669a79 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 """