Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
7977766
Bump typer from 0.27.3 to 0.28.0
dependabot[bot] Nov 16, 2026
fe5f89f
Bump ruff from 0.17.3 to 0.17.4
dependabot[bot] Nov 16, 2026
471ac2a
Bump cachetools from 7.2.8 to 7.3.0
dependabot[bot] Nov 16, 2026
ba2ef16
Bump specifications/json-ld-api from `92f0770` to `5551473`
dependabot[bot] Nov 16, 2026
0e74c4a
Fix misspelled 'embedded' state key in reverse framing
afeefaa333 Nov 16, 2026
cdaf832
Add regression test for @embed @never in reverse frames
afeefaa333 Nov 16, 2026
40ee368
Add changelog entry for #378
afeefaa333 Nov 17, 2026
270be16
fix: resolve references against a base without a path as RFC 3986 does
jdsika Nov 4, 2026
1bdd30f
test: resolve absolute paths and dot segments against a base without …
jdsika Nov 4, 2026
b51a50c
docs: add the base without a path fix to the changelog
jdsika Nov 4, 2026
39a4e8e
fix: drop the base query when resolving a path against a base without…
jdsika Nov 4, 2026
fe87084
test: resolve dot segments in queries and against a base with a query
jdsika Nov 4, 2026
86aeee4
docs: complete the base without a path changelog entry
jdsika Nov 4, 2026
8ae2320
fix: ignore the query of the base IRI when resolving a path
jdsika Nov 4, 2026
bed7b96
test: resolve paths against bases with a query that contains a slash
jdsika Nov 4, 2026
8f85f59
docs: describe the base query fix in the changelog
jdsika Nov 4, 2026
3cd7f87
test: resolve dot references against a base without a path
jdsika Nov 10, 2026
bb919f4
docs: shorten the base without a path changelog entry
jdsika Nov 10, 2026
d31287a
fix: remove dot segments from the path of a reference only, not from …
jdsika Nov 10, 2026
1c06041
test: pin dot segments before a query or fragment and rename the base…
jdsika Nov 10, 2026
5eaa134
docs: describe the exact resolver changes in the changelog
jdsika Nov 10, 2026
c7c0314
fix: keep the dot of a path segment that starts with a dot
jdsika Nov 10, 2026
f57cc9b
test: keep the dot of a path segment that starts with a dot
jdsika Nov 10, 2026
bb6e51d
refactor: drop the base query in one place
jdsika Nov 10, 2026
6bd3e83
refactor: split the reference only where its path is resolved
jdsika Nov 10, 2026
54a422a
test: cover a root path and a first segment starting with a dot
jdsika Nov 10, 2026
ecd80d4
docs: shorten and scope the resolver changelog entry
jdsika Nov 10, 2026
a84f405
fix: keep the slash of a final dot segment before a query or fragment
jdsika Nov 12, 2026
a58cafa
refactor: stop splitting the reference before removing dot segments
jdsika Nov 12, 2026
9139185
test: cover a base IRI whose only colon is in its query
jdsika Nov 12, 2026
b87fa3e
docs: note the remove_dot_segments() slash fix in the changelog
jdsika Nov 12, 2026
0404ae0
fix: treat a reference with a slash before its first colon as a relat…
jdsika Nov 4, 2026
bae554f
test: resolve references with a slash before a colon
jdsika Nov 4, 2026
0e64cc2
docs: add the relative IRI colon fix to the changelog
jdsika Nov 4, 2026
34156f7
fix: also treat a reference with ? or # before its first colon as rel…
jdsika Nov 4, 2026
9c07761
test: resolve references with ? or # before a colon and dot segments
jdsika Nov 4, 2026
a01d4bb
docs: mention ? and # in the relative IRI colon changelog entry
jdsika Nov 4, 2026
3d5dc39
fix: start the path before any query or fragment when removing dot se…
jdsika Nov 4, 2026
908d12d
test: keep dot segments in a query or fragment
jdsika Nov 4, 2026
128b99d
docs: mention dot segments in queries in the relative IRI colon chang…
jdsika Nov 4, 2026
0088875
test: cover a colon and a dot segment before a query
jdsika Nov 12, 2026
c537119
refactor: pass -1 once the reference is known to have no scheme
jdsika Nov 12, 2026
7869e82
test: cover dot segments before a colon as relative-to-absolute-iri.j…
jdsika Nov 12, 2026
c9290d4
docs: say that the colon fix applies against a base IRI
jdsika Nov 12, 2026
b2276dd
Update CHANGELOG.md
jdsika Nov 23, 2026
1fc4d1d
Update CHANGELOG.md
jdsika Nov 23, 2026
c10d600
build(deps): bump cachetools from 7.3.0 to 7.3.2
dependabot[bot] Nov 23, 2026
0647d36
build(deps-dev): bump ruff from 0.17.4 to 0.17.5
dependabot[bot] Nov 23, 2026
fbb894e
build(deps): bump specifications/json-ld-api from `5551473` to `a1732db`
dependabot[bot] Nov 23, 2026
c9a68bc
build(deps): bump specifications/rdf-canon from `15619df` to `5ffaaa1`
dependabot[bot] Nov 23, 2026
e74dc67
fix: use a term as a prefix only if its name has no colon or slash
jdsika Nov 25, 2026
557a673
test: expand values after a term whose name contains a slash
jdsika Nov 25, 2026
2aa67b8
test: do not compact to a prefix term whose name contains a slash
jdsika Nov 25, 2026
a50319e
docs: add the term with a slash prefix fix to the changelog
jdsika Nov 25, 2026
0474030
fix: build a compact IRI only from a prefix term, also when it is a term
jdsika Nov 25, 2026
7b2ef3a
test: round-trip compact IRIs from terms that are no prefix
jdsika Nov 25, 2026
eb5b575
docs: add the compact IRI prefix fix to the changelog
jdsika Nov 25, 2026
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

- Preserved RDF literal lexical forms when converting through RDFLib, including canonical double output, large numeric values, and compound literal handling.
- Fixed the active context clone dropping the default base direction: `@direction` now survives context layers like `@language`. Fixes [issue #337](https://github.com/digitalbazaar/pyld/issues/337).
- Fixed `@embed: @never` being ignored for reverse-framed properties because of a misspelled `embedded` framing state key. Fixes [issue #378](https://github.com/digitalbazaar/pyld/issues/378).
- Fixed `KeyError` when a context sets `@direction: null` and no default base direction is in effect.
- Fixed `iri_resolver.unresolve()` query/fragment reconstruction while cleaning up the resolver docstring.
- Invalid IRI base values within lists are now skipped when serializing to RDF. Fixes [toRdf#tli12](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tli12) and [toRdf#tli14](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tli14).
Expand All @@ -33,6 +34,12 @@
- Use a helper for generalized N-Quads normalization in the test runner, since rdflib cannot parse blank-node predicates. Fixes [toRdf#te075](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te075).
- `jsonld.expand()`, `jsonld.to_rdf()` and the other operations no longer fail with an `OverflowError` for an integer too large for a double. `jsonld.to_rdf()` writes it as `INF` or `-INF`, the infinite `xsd:double` values, or, in `json-ld-1.0` mode and not typed as `xsd:double`, as an exact `xsd:integer`. Inside `@json` literals, `jsonld.to_rdf()` and `jsonld.normalize()` still raise `OverflowError` for such numbers, as RFC 8785 only allows numbers that fit in a double.
- `jsonld.to_rdf()` writes the `xsd:double` NaN as `NaN`, its XSD canonical form, instead of `NAN`, so `jsonld.normalize()` output changes for documents with such a value.
- Fixed `iri_resolver.resolve()` to
- fix references without a scheme or host against a base IRI with a host and no path (`/x` against `http://example.org` gave `http://example.org//x`) or with a query, and keeps the dot of a first segment such as `.gh`.
- treat a reference with a `/`, `?` or `#` before its first `:`, such as `/a:b`, `x/y:z` or `a?b:c`, as a relative IRI and resolves it against the base IRI, as RFC 3986 does. It was returned unresolved, so `jsonld.to_rdf()` dropped it.
- `iri_resolver.remove_dot_segments()`, and with it `iri_resolver.resolve()`, no longer drops the `/` that a final `.` or `..` segment leaves before a query or fragment (`/a/.?x` gave `/a?x`).
- A term whose name contains a `:` or a `/`, such as `/a/`, is no longer a prefix, as [Create Term Definition](https://www.w3.org/TR/json-ld11-api/#create-term-definition) step 14.2.5 requires. `jsonld.expand()` read `/a/:b` as a compact IRI with that term instead of as a relative IRI, and `jsonld.compact()` wrote such compact IRIs. A context with a term such as `/a/:b` can now fail, or newly pass, the check that the term expands to its own IRI.
- `jsonld.compact()` builds a compact IRI only from a term with the prefix flag, as [IRI Compaction](https://www.w3.org/TR/json-ld11-api/#iri-compaction) step 7.1 requires, also when the compact IRI is itself a term for the IRI. With `{"ex": "http://example.org/ns", "ex:foo": {"@type": "@id"}}`, `http://example.org/nsfoo` was compacted to `ex:foo`, which doesn't expand back to it.

### Changed
- **BREAKING**: Developer install, command execution, documentation, and release artifact
Expand Down
72 changes: 37 additions & 35 deletions lib/pyld/iri_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ def remove_dot_segments(path: str) -> str:
if segment_buffers:
segment_buffers.pop()

# Add trailing slash segment if ends with '/..'
if i + 3 >= length:
# Add trailing slash segment if the path ends with '/..',
# also before a query or fragment
if next_ch != '/':
segment_buffers.append([])

i += 3
Expand All @@ -60,8 +61,9 @@ def remove_dot_segments(path: str) -> str:
i += 1
continue

# Add trailing slash if ends with '/.'
if i + 2 >= length:
# Add trailing slash if the path ends with '/.',
# also before a query or fragment
if next_ch != '/':
segment_buffers.append([])

# Stay in current directory — skip
Expand Down Expand Up @@ -97,7 +99,8 @@ def remove_dot_segments_of_path(iri: str, colon_position: int) -> str:
Remove dot segments from the path portion of an IRI (RFC 3986 §5.2.4).

:param iri: an IRI (or part of IRI).
:param colonPosition: the position of the first ':' in the IRI.
:param colon_position: the position of the ':' that ends the scheme of the
IRI, or -1 if it has no scheme.

:return: the IRI where dot segments were removed.
"""
Expand All @@ -114,9 +117,12 @@ def remove_dot_segments_of_path(iri: str, colon_position: int) -> str:
else:
search_offset = 2 if len(iri) > 1 and iri[0] == '/' and iri[1] == '/' else 0

# Find the start of the path
# Find the start of the path: the first '/', unless a query or fragment
# starts before it
path_separator = iri.find('/', search_offset)
if path_separator < 0:
if path_separator < 0 or any(
ch in iri[search_offset:path_separator] for ch in '?#'
):
return iri

base = iri[:path_separator]
Expand Down Expand Up @@ -150,17 +156,20 @@ def resolve(relative_iri: str, base_iri: str = None) -> str:
)
return base_iri

# If the value starts with a query character, concat directly (strip existing query)
if relative_iri.startswith("?"):
base_query_pos = base_iri.find("?")
if base_query_pos > 0:
base_iri = base_iri[:base_query_pos]
return base_iri + relative_iri

# If the value starts with a fragment character, concat directly
if relative_iri.startswith("#"):
return base_iri + relative_iri

# The query of the base IRI only applies to an empty value or a fragment
# (RFC 3986, section 5.2.2)
base_query_pos = base_iri.find("?")
if base_query_pos > 0:
base_iri = base_iri[:base_query_pos]

# If the value starts with a query character, concat directly
if relative_iri.startswith("?"):
return base_iri + relative_iri

# Ignore baseIRI if it is empty
if not base_iri:
relative_colon_pos = relative_iri.find(":")
Expand All @@ -170,10 +179,15 @@ def resolve(relative_iri: str, base_iri: str = None) -> str:
)
return remove_dot_segments_of_path(relative_iri, relative_colon_pos)

# Ignore baseIRI if the value is absolute
# Ignore baseIRI if the value is absolute.
# Per RFC 3986, a URI scheme cannot contain a '/', '?' or '#', so if one of
# them appears before the first ':', the IRI is relative (not absolute).
value_colon_pos = relative_iri.find(":")
if value_colon_pos >= 0:
if value_colon_pos >= 0 and not any(
ch in relative_iri[:value_colon_pos] for ch in "/?#"
):
return remove_dot_segments_of_path(relative_iri, value_colon_pos)
# From here on, the value has no scheme: a ':' in it does not end a scheme.

# baseIRI must be absolute
base_colon_pos = base_iri.find(":")
Expand All @@ -186,28 +200,23 @@ def resolve(relative_iri: str, base_iri: str = None) -> str:

# Inherit base scheme if relative starts with '//'
if relative_iri.startswith("//"):
return base_scheme + remove_dot_segments_of_path(relative_iri, value_colon_pos)
return base_scheme + remove_dot_segments_of_path(relative_iri, -1)

# Determine where the path of base starts
if base_iri.find("//", base_colon_pos) == base_colon_pos + 1:
base_slash_after_colon_pos = base_iri.find("/", base_colon_pos + 3)
if base_slash_after_colon_pos < 0:
if len(base_iri) > base_colon_pos + 3:
return (
base_iri
+ "/"
+ remove_dot_segments_of_path(relative_iri, value_colon_pos)
)
# The base has an authority and an empty path, so its path is
# taken as '/' (RFC 3986, section 5.2.3)
base_iri += "/"
base_slash_after_colon_pos = len(base_iri) - 1
else:
return base_scheme + remove_dot_segments_of_path(
relative_iri, value_colon_pos
)
return base_scheme + remove_dot_segments_of_path(relative_iri, -1)
else:
base_slash_after_colon_pos = base_iri.find("/", base_colon_pos + 1)
if base_slash_after_colon_pos < 0:
return base_scheme + remove_dot_segments_of_path(
relative_iri, value_colon_pos
)
return base_scheme + remove_dot_segments_of_path(relative_iri, -1)

# If relative starts with '/', append after base authority
if relative_iri.startswith("/"):
Expand All @@ -219,13 +228,6 @@ def resolve(relative_iri: str, base_iri: str = None) -> str:
# Ignore everything after last '/' in base path
if last_slash >= 0 and last_slash < len(base_path) - 1:
base_path = base_path[: last_slash + 1]
if (
relative_iri.startswith(".")
and not relative_iri.startswith("..")
and not relative_iri.startswith("./")
and len(relative_iri) > 2
):
relative_iri = relative_iri[1:]

relative_iri = base_path + relative_iri
relative_iri = remove_dot_segments(relative_iri)
Expand Down
14 changes: 8 additions & 6 deletions lib/pyld/jsonld.py
Original file line number Diff line number Diff line change
Expand Up @@ -4660,7 +4660,7 @@ def _match_frame(self, state, subjects, frame, parent, property):
{'propertyIsArray': True},
)
self._match_frame(
{**state, 'embeded': True},
{**state, 'embedded': True},
[subject],
subframe,
output['@reverse'][reverse_prop],
Expand Down Expand Up @@ -5398,14 +5398,13 @@ def _compact_iri(
):
continue

# a CURIE is usable if:
# a CURIE is usable if the term is a prefix and:
# 1. it has no mapping, OR
# 2. value is None, which means we're not compacting an @value, AND
# the mapping matches the IRI
curie = term + ':' + iri[len(definition['@id']) :]
is_usable_curie = (
active_ctx['mappings'][term]['_prefix']
and curie not in active_ctx['mappings']
is_usable_curie = active_ctx['mappings'][term]['_prefix'] and (
curie not in active_ctx['mappings']
or (
value is None
and active_ctx['mappings'].get(curie, {}).get('@id') == iri
Expand Down Expand Up @@ -5802,9 +5801,12 @@ def _create_term_definition(
)

mapping['@id'] = id_
# only a simple term without ':' or '/' may be a prefix
# (Create Term Definition, step 14.2.5)
mapping['_prefix'] = (
_simple_term
and not mapping['_term_has_colon']
and ':' not in term
and '/' not in term
and (
id_.startswith('_:')
or bool(re.match(r'.*[:/\?#\[\]@]$', id_))
Expand Down
2 changes: 1 addition & 1 deletion specifications/rdf-canon
18 changes: 17 additions & 1 deletion tests/iri_resolver/test_remove_dot_segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_not_modify_parent_paths_in_queries():


def test_mixed_current_and_parent_with_fragment():
assert remove_dot_segments('/abc/def/./ghi/../..#abc') == '/abc#abc'
assert remove_dot_segments('/abc/def/./ghi/../..#abc') == '/abc/#abc'


def test_fragment_without_another_path():
Expand Down Expand Up @@ -151,6 +151,22 @@ def test_end_with_slash_if_trailing_slash_dot():
assert remove_dot_segments('/a/bb/ccc/./g/.') == '/a/bb/ccc/g/'


def test_end_with_slash_if_slash_dot_before_query():
assert remove_dot_segments('/abc/def/.?a=b') == '/abc/def/?a=b'


def test_end_with_slash_if_slash_dot_before_fragment():
assert remove_dot_segments('/abc/def/.#abc') == '/abc/def/#abc'


def test_end_with_slash_if_slash_double_dot_before_query():
assert remove_dot_segments('/abc/def/..?a=b') == '/abc/?a=b'


def test_end_with_slash_if_slash_double_dot_before_fragment():
assert remove_dot_segments('/abc/def/..#abc') == '/abc/#abc'


def test_triple_dots_as_normal_segment():
assert remove_dot_segments('/invalid/...') == '/invalid/...'

Expand Down
Loading
Loading