Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8d3f9a3
fix: resolve references against a base without a path as RFC 3986 does
jdsika Nov 4, 2026
77de121
test: resolve absolute paths and dot segments against a base without …
jdsika Nov 4, 2026
4320552
docs: add the base without a path fix to the changelog
jdsika Nov 4, 2026
29a80bf
fix: drop the base query when resolving a path against a base without…
jdsika Nov 4, 2026
a2836ad
test: resolve dot segments in queries and against a base with a query
jdsika Nov 4, 2026
a9296ee
docs: complete the base without a path changelog entry
jdsika Nov 4, 2026
34bea18
fix: ignore the query of the base IRI when resolving a path
jdsika Nov 4, 2026
56165a6
test: resolve paths against bases with a query that contains a slash
jdsika Nov 4, 2026
b6409d8
docs: describe the base query fix in the changelog
jdsika Nov 4, 2026
e22a701
test: resolve dot references against a base without a path
jdsika Nov 10, 2026
e241535
docs: shorten the base without a path changelog entry
jdsika Nov 10, 2026
48ae749
fix: remove dot segments from the path of a reference only, not from …
jdsika Nov 10, 2026
ac47c89
test: pin dot segments before a query or fragment and rename the base…
jdsika Nov 10, 2026
e093d97
docs: describe the exact resolver changes in the changelog
jdsika Nov 10, 2026
50092b8
fix: keep the dot of a path segment that starts with a dot
jdsika Nov 10, 2026
30c5393
test: keep the dot of a path segment that starts with a dot
jdsika Nov 10, 2026
fbfdc1a
refactor: drop the base query in one place
jdsika Nov 10, 2026
593c9d2
refactor: split the reference only where its path is resolved
jdsika Nov 10, 2026
1d1530f
test: cover a root path and a first segment starting with a dot
jdsika Nov 10, 2026
e93f768
docs: shorten and scope the resolver changelog entry
jdsika Nov 10, 2026
347b036
fix: keep the slash of a final dot segment before a query or fragment
jdsika Nov 12, 2026
fe6ed5b
refactor: stop splitting the reference before removing dot segments
jdsika Nov 12, 2026
a326f69
test: cover a base IRI whose only colon is in its query
jdsika Nov 12, 2026
0dcdfdc
docs: note the remove_dot_segments() slash fix in the changelog
jdsika Nov 12, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
- 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.
- `iri_resolver.resolve()` fixes 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`.
- `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`).

### Changed
- **BREAKING**: Developer install, command execution, documentation, and release artifact
Expand Down
43 changes: 20 additions & 23 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 @@ -150,17 +152,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 Down Expand Up @@ -193,11 +198,10 @@ def resolve(relative_iri: str, base_iri: str = None) -> str:
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
Expand All @@ -219,13 +223,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
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
102 changes: 102 additions & 0 deletions tests/iri_resolver/test_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ def test_non_absolute_base_error():
resolve('abc', 'def')


def test_base_without_scheme_colon_only_in_query_error():
with pytest.raises(
ValueError, match=r"Found invalid baseIRI 'def' for value 'abc'"
):
resolve('abc', 'def?x:y')


def test_non_absolute_base_empty_value_error():
with pytest.raises(ValueError, match=r"Found invalid baseIRI 'def' for value ''"):
resolve('', 'def')
Expand All @@ -80,6 +87,101 @@ def test_base_without_path_dot_segments():
assert resolve('abc/./', 'http://base.org') == 'http://base.org/abc/'


def test_base_without_path_root_path():
assert resolve('/', 'http://base.org') == 'http://base.org/'


def test_base_without_path_absolute_path():
assert resolve('/abc', 'http://base.org') == 'http://base.org/abc'


def test_base_without_path_absolute_path_with_dot_segments():
assert resolve('/abc/../def', 'http://base.org') == 'http://base.org/def'


def test_base_without_path_parent_segment():
assert resolve('../abc', 'http://base.org') == 'http://base.org/abc'


def test_base_without_path_relative_with_query():
assert resolve('abc?x=1', 'http://base.org') == 'http://base.org/abc?x=1'


def test_base_without_path_dot_segments_in_query():
assert resolve('abc?x=/../y', 'http://base.org') == 'http://base.org/abc?x=/../y'


def test_base_without_path_double_dot():
assert resolve('..', 'http://base.org') == 'http://base.org/'


def test_base_without_path_dot():
assert resolve('.', 'http://base.org') == 'http://base.org/'


def test_base_without_path_dot_slash():
assert resolve('./', 'http://base.org') == 'http://base.org/'


def test_base_without_path_dot_slash_segment():
assert resolve('./abc', 'http://base.org') == 'http://base.org/abc'


def test_base_without_path_dot_segment_before_query():
assert resolve('abc/.?x', 'http://base.org') == 'http://base.org/abc/?x'


def test_base_without_path_double_dot_segment_before_fragment():
assert resolve('abc/def/..#x', 'http://base.org') == 'http://base.org/abc/#x'


def test_base_without_path_ignores_base_query():
assert resolve('abc', 'http://base.org?q') == 'http://base.org/abc'


def test_base_without_path_relative_with_dot_segments():
assert resolve('abc/../def', 'http://base.org') == 'http://base.org/def'


def test_base_without_path_with_slash_in_query():
assert resolve('/', 'http://base.org?a/b') == 'http://base.org/'


def test_base_with_slash_in_query():
assert resolve('jjj', 'http://abc/def?ghi/jkl') == 'http://abc/jjj'


def test_base_dot_segment_before_query():
assert resolve('abc/.?x', 'http://base.org/') == 'http://base.org/abc/?x'


def test_base_with_query_dot_before_query():
assert resolve('.?y', 'http://abc/def/?x') == 'http://abc/def/?y'


def test_base_with_query_dot_before_fragment():
assert resolve('.#y', 'http://abc/def/?x') == 'http://abc/def/#y'


def test_base_segment_starting_with_dot():
assert resolve('.gh', 'http://example.org/a') == 'http://example.org/.gh'


def test_base_first_segment_starting_with_dot():
assert (
resolve('.x/a', 'http://ex.org/x/yy/zzz/f.ttl')
== 'http://ex.org/x/yy/zzz/.x/a'
)


def test_absolute_dot_segment_before_query():
assert resolve('http://abc/def/.?x') == 'http://abc/def/?x'


def test_network_path_double_dot_segment_before_fragment():
assert resolve('//abc/def/ghi/..#x', 'http://base.org/') == 'http://abc/def/#x'


def test_base_only_scheme_slash_slash():
assert resolve('abc', 'http://') == 'http:abc'

Expand Down
Loading