From 8d3f9a32cef2f30338461fabe6643b28008b6f0c Mon Sep 17 00:00:00 2001 From: jdsika Date: Wed, 4 Nov 2026 14:22:30 +0100 Subject: [PATCH 01/24] fix: resolve references against a base without a path as RFC 3986 does Signed-off-by: jdsika --- lib/pyld/iri_resolver.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/pyld/iri_resolver.py b/lib/pyld/iri_resolver.py index 2090a68fa..5535391d5 100644 --- a/lib/pyld/iri_resolver.py +++ b/lib/pyld/iri_resolver.py @@ -193,11 +193,12 @@ 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: a path-relative + # reference is merged with "/" (RFC 3986, section 5.2.3), an + # absolute path is used as it is, and dot segments are removed. + if not relative_iri.startswith("/"): + relative_iri = "/" + relative_iri + return base_iri + remove_dot_segments(relative_iri) else: return base_scheme + remove_dot_segments_of_path( relative_iri, value_colon_pos From 77de121259af4fddc9e4acfb77413c9d1e515246 Mon Sep 17 00:00:00 2001 From: jdsika Date: Wed, 4 Nov 2026 14:22:31 +0100 Subject: [PATCH 02/24] test: resolve absolute paths and dot segments against a base without a path Signed-off-by: jdsika --- tests/iri_resolver/test_resolve.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/iri_resolver/test_resolve.py b/tests/iri_resolver/test_resolve.py index 92082e33b..5e4a82695 100644 --- a/tests/iri_resolver/test_resolve.py +++ b/tests/iri_resolver/test_resolve.py @@ -80,6 +80,22 @@ def test_base_without_path_dot_segments(): assert resolve('abc/./', 'http://base.org') == 'http://base.org/abc/' +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_query(): + assert resolve('abc?x=1', 'http://base.org') == 'http://base.org/abc?x=1' + + def test_base_only_scheme_slash_slash(): assert resolve('abc', 'http://') == 'http:abc' From 43205521173c802759740bd218e23871190205fa Mon Sep 17 00:00:00 2001 From: jdsika Date: Wed, 4 Nov 2026 14:22:31 +0100 Subject: [PATCH 03/24] docs: add the base without a path fix to the changelog Signed-off-by: jdsika --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71166a9b0..f03f7436b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ - 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()` resolves a reference against a base with an authority and an empty path, such as `http://example.org`, as RFC 3986 does: `/x` became `http://example.org//x`, and dot segments in a path-relative reference were kept. ### Changed - **BREAKING**: Developer install, command execution, documentation, and release artifact From 29a80bfe29727d9e71ad563807c13a91f8d15e51 Mon Sep 17 00:00:00 2001 From: jdsika Date: Wed, 4 Nov 2026 14:36:08 +0100 Subject: [PATCH 04/24] fix: drop the base query when resolving a path against a base without a path Signed-off-by: jdsika --- lib/pyld/iri_resolver.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/pyld/iri_resolver.py b/lib/pyld/iri_resolver.py index 5535391d5..277998fea 100644 --- a/lib/pyld/iri_resolver.py +++ b/lib/pyld/iri_resolver.py @@ -196,8 +196,12 @@ def resolve(relative_iri: str, base_iri: str = None) -> str: # The base has an authority and an empty path: a path-relative # reference is merged with "/" (RFC 3986, section 5.2.3), an # absolute path is used as it is, and dot segments are removed. + # A query of the base does not apply to a path reference. if not relative_iri.startswith("/"): relative_iri = "/" + relative_iri + base_query_pos = base_iri.find("?") + if base_query_pos > 0: + base_iri = base_iri[:base_query_pos] return base_iri + remove_dot_segments(relative_iri) else: return base_scheme + remove_dot_segments_of_path( From a2836ad97de373f429e48796167468d049318736 Mon Sep 17 00:00:00 2001 From: jdsika Date: Wed, 4 Nov 2026 14:36:09 +0100 Subject: [PATCH 05/24] test: resolve dot segments in queries and against a base with a query Signed-off-by: jdsika --- tests/iri_resolver/test_resolve.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/iri_resolver/test_resolve.py b/tests/iri_resolver/test_resolve.py index 5e4a82695..b121ff25f 100644 --- a/tests/iri_resolver/test_resolve.py +++ b/tests/iri_resolver/test_resolve.py @@ -96,6 +96,18 @@ def test_base_without_path_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_with_query(): + assert resolve('abc', 'http://base.org?q') == 'http://base.org/abc' + + def test_base_only_scheme_slash_slash(): assert resolve('abc', 'http://') == 'http:abc' From a9296eeb6470876888d434174530a8fe4655cc66 Mon Sep 17 00:00:00 2001 From: jdsika Date: Wed, 4 Nov 2026 14:36:09 +0100 Subject: [PATCH 06/24] docs: complete the base without a path changelog entry Signed-off-by: jdsika --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f03f7436b..495096ee3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,7 +33,7 @@ - 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()` resolves a reference against a base with an authority and an empty path, such as `http://example.org`, as RFC 3986 does: `/x` became `http://example.org//x`, and dot segments in a path-relative reference were kept. +- `iri_resolver.resolve()` resolves a reference against a base with an authority and an empty path, such as `http://example.org`, as RFC 3986 does: `/x` became `http://example.org//x`, dot segments were kept in a path and removed from a query, and a base query was kept before the path. ### Changed - **BREAKING**: Developer install, command execution, documentation, and release artifact From 34bea18ab57ea45b67569d5d06c8a61ec0f2b4a4 Mon Sep 17 00:00:00 2001 From: jdsika Date: Wed, 4 Nov 2026 15:13:19 +0100 Subject: [PATCH 07/24] fix: ignore the query of the base IRI when resolving a path Signed-off-by: jdsika --- lib/pyld/iri_resolver.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/pyld/iri_resolver.py b/lib/pyld/iri_resolver.py index 277998fea..5989fd5b8 100644 --- a/lib/pyld/iri_resolver.py +++ b/lib/pyld/iri_resolver.py @@ -161,6 +161,12 @@ def resolve(relative_iri: str, base_iri: str = None) -> str: 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_iri_query_pos = base_iri.find("?") + if base_iri_query_pos > 0: + base_iri = base_iri[:base_iri_query_pos] + # Ignore baseIRI if it is empty if not base_iri: relative_colon_pos = relative_iri.find(":") @@ -196,12 +202,8 @@ def resolve(relative_iri: str, base_iri: str = None) -> str: # The base has an authority and an empty path: a path-relative # reference is merged with "/" (RFC 3986, section 5.2.3), an # absolute path is used as it is, and dot segments are removed. - # A query of the base does not apply to a path reference. if not relative_iri.startswith("/"): relative_iri = "/" + relative_iri - base_query_pos = base_iri.find("?") - if base_query_pos > 0: - base_iri = base_iri[:base_query_pos] return base_iri + remove_dot_segments(relative_iri) else: return base_scheme + remove_dot_segments_of_path( From 56165a6a60b83dd455bf2ca92e9587270bbd54b0 Mon Sep 17 00:00:00 2001 From: jdsika Date: Wed, 4 Nov 2026 15:13:20 +0100 Subject: [PATCH 08/24] test: resolve paths against bases with a query that contains a slash Signed-off-by: jdsika --- tests/iri_resolver/test_resolve.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/iri_resolver/test_resolve.py b/tests/iri_resolver/test_resolve.py index b121ff25f..256964a93 100644 --- a/tests/iri_resolver/test_resolve.py +++ b/tests/iri_resolver/test_resolve.py @@ -108,6 +108,18 @@ def test_base_without_path_with_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_only_scheme_slash_slash(): assert resolve('abc', 'http://') == 'http:abc' From b6409d800960258196ad165342eda8cedc2b35c8 Mon Sep 17 00:00:00 2001 From: jdsika Date: Wed, 4 Nov 2026 15:13:20 +0100 Subject: [PATCH 09/24] docs: describe the base query fix in the changelog Signed-off-by: jdsika --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 495096ee3..153109ef1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,7 +33,7 @@ - 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()` resolves a reference against a base with an authority and an empty path, such as `http://example.org`, as RFC 3986 does: `/x` became `http://example.org//x`, dot segments were kept in a path and removed from a query, and a base query was kept before the path. +- `iri_resolver.resolve()` resolves a reference against a base with an authority and an empty path, such as `http://example.org`, as RFC 3986 does: `/x` became `http://example.org//x`, and dot segments were kept in a path and removed from a query. The query of the base IRI no longer stays in front of a path, or counts as part of the base path when it contains a `/`. ### Changed - **BREAKING**: Developer install, command execution, documentation, and release artifact From e22a7010a69cc92278cbc5c29991c366f72af4a4 Mon Sep 17 00:00:00 2001 From: jdsika Date: Tue, 10 Nov 2026 13:46:29 +0100 Subject: [PATCH 10/24] test: resolve dot references against a base without a path Signed-off-by: jdsika --- tests/iri_resolver/test_resolve.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/iri_resolver/test_resolve.py b/tests/iri_resolver/test_resolve.py index 256964a93..a8aa332fb 100644 --- a/tests/iri_resolver/test_resolve.py +++ b/tests/iri_resolver/test_resolve.py @@ -104,6 +104,18 @@ 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_with_query(): assert resolve('abc', 'http://base.org?q') == 'http://base.org/abc' From e2415351f154a4e35ae0744e56b8faa475e983b2 Mon Sep 17 00:00:00 2001 From: jdsika Date: Tue, 10 Nov 2026 13:46:29 +0100 Subject: [PATCH 11/24] docs: shorten the base without a path changelog entry Signed-off-by: jdsika --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 153109ef1..57e814ee1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,7 +33,7 @@ - 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()` resolves a reference against a base with an authority and an empty path, such as `http://example.org`, as RFC 3986 does: `/x` became `http://example.org//x`, and dot segments were kept in a path and removed from a query. The query of the base IRI no longer stays in front of a path, or counts as part of the base path when it contains a `/`. +- `iri_resolver.resolve()` now follows RFC 3986 §5.2 when the base IRI has an empty path or a query: `/x` against `http://example.org` gives `http://example.org/x` instead of `http://example.org//x`, dot segments are removed from the path and not the query, and the base query no longer carries over to a reference with a path. ### Changed - **BREAKING**: Developer install, command execution, documentation, and release artifact From 48ae749a201d30b08f8b18d64c0a12c231ab46c0 Mon Sep 17 00:00:00 2001 From: jdsika Date: Tue, 10 Nov 2026 14:14:39 +0100 Subject: [PATCH 12/24] fix: remove dot segments from the path of a reference only, not from its query or fragment Signed-off-by: jdsika --- lib/pyld/iri_resolver.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/pyld/iri_resolver.py b/lib/pyld/iri_resolver.py index 5989fd5b8..137274df5 100644 --- a/lib/pyld/iri_resolver.py +++ b/lib/pyld/iri_resolver.py @@ -7,6 +7,7 @@ .. moduleauthor:: Miel Vander Sande """ +import re from urllib.parse import ParseResult, urlparse, urlunparse @@ -194,31 +195,39 @@ def resolve(relative_iri: str, base_iri: str = None) -> str: if relative_iri.startswith("//"): return base_scheme + remove_dot_segments_of_path(relative_iri, value_colon_pos) + # Dot segments are only removed from the path of the value, which ends at + # the first '?' or '#' (RFC 3986, section 5.2.2) + path_end = re.search(r"[?#]|\Z", relative_iri).start() + query_and_fragment = relative_iri[path_end:] + relative_iri = relative_iri[:path_end] + # 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: - # The base has an authority and an empty path: a path-relative - # reference is merged with "/" (RFC 3986, section 5.2.3), an - # absolute path is used as it is, and dot segments are removed. - if not relative_iri.startswith("/"): - relative_iri = "/" + relative_iri - return base_iri + remove_dot_segments(relative_iri) + # 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 + relative_iri + query_and_fragment, value_colon_pos ) 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 + relative_iri + query_and_fragment, value_colon_pos ) # If relative starts with '/', append after base authority if relative_iri.startswith("/"): - return base_iri[:base_slash_after_colon_pos] + remove_dot_segments(relative_iri) + return ( + base_iri[:base_slash_after_colon_pos] + + remove_dot_segments(relative_iri) + + query_and_fragment + ) base_path = base_iri[base_slash_after_colon_pos:] last_slash = base_path.rfind("/") @@ -237,7 +246,7 @@ def resolve(relative_iri: str, base_iri: str = None) -> str: relative_iri = base_path + relative_iri relative_iri = remove_dot_segments(relative_iri) - return base_iri[:base_slash_after_colon_pos] + relative_iri + return base_iri[:base_slash_after_colon_pos] + relative_iri + query_and_fragment def unresolve(absolute_iri: str, base_iri: str = ""): From ac47c89bde6f37928823afc9cd40589a15cbe478 Mon Sep 17 00:00:00 2001 From: jdsika Date: Tue, 10 Nov 2026 14:14:40 +0100 Subject: [PATCH 13/24] test: pin dot segments before a query or fragment and rename the base query tests Signed-off-by: jdsika --- tests/iri_resolver/test_resolve.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/iri_resolver/test_resolve.py b/tests/iri_resolver/test_resolve.py index a8aa332fb..10d4662bd 100644 --- a/tests/iri_resolver/test_resolve.py +++ b/tests/iri_resolver/test_resolve.py @@ -92,7 +92,7 @@ def test_base_without_path_parent_segment(): assert resolve('../abc', 'http://base.org') == 'http://base.org/abc' -def test_base_without_path_query(): +def test_base_without_path_relative_with_query(): assert resolve('abc?x=1', 'http://base.org') == 'http://base.org/abc?x=1' @@ -116,7 +116,15 @@ def test_base_without_path_dot_slash_segment(): assert resolve('./abc', 'http://base.org') == 'http://base.org/abc' -def test_base_without_path_with_query(): +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' @@ -132,6 +140,18 @@ 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_only_scheme_slash_slash(): assert resolve('abc', 'http://') == 'http:abc' From e093d97960d5476e361b63e3df2ae31d7a660e26 Mon Sep 17 00:00:00 2001 From: jdsika Date: Tue, 10 Nov 2026 14:14:40 +0100 Subject: [PATCH 14/24] docs: describe the exact resolver changes in the changelog Signed-off-by: jdsika --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57e814ee1..538ef3794 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,7 +33,7 @@ - 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()` now follows RFC 3986 §5.2 when the base IRI has an empty path or a query: `/x` against `http://example.org` gives `http://example.org/x` instead of `http://example.org//x`, dot segments are removed from the path and not the query, and the base query no longer carries over to a reference with a path. +- `iri_resolver.resolve()` ignores the base IRI's query when the reference has a path. Against a base IRI with a host, it merges the reference with `/` when the base has no path, removes dot segments from the reference's path only, not from its query or fragment, and keeps the dot of a segment such as `.gh`. For example, `/x` and `./x` against `http://example.org` gave `http://example.org//x` and `http://example.org/./x`, `x` against `http://example.org?q` gave `http://example.org?q/x`, `a/.?x` against `http://example.org/` gave `http://example.org/a?x`, and `.gh` against `http://example.org/a` gave `http://example.org/gh`. ### Changed - **BREAKING**: Developer install, command execution, documentation, and release artifact From 50092b8889d1b3bfe8a70b3e7ef5e2feab6da6c4 Mon Sep 17 00:00:00 2001 From: jdsika Date: Tue, 10 Nov 2026 14:18:25 +0100 Subject: [PATCH 15/24] fix: keep the dot of a path segment that starts with a dot Signed-off-by: jdsika --- lib/pyld/iri_resolver.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/pyld/iri_resolver.py b/lib/pyld/iri_resolver.py index 137274df5..fe8bdd594 100644 --- a/lib/pyld/iri_resolver.py +++ b/lib/pyld/iri_resolver.py @@ -235,13 +235,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) From 30c53935bf92b514f55ed235f548a3ac9a676409 Mon Sep 17 00:00:00 2001 From: jdsika Date: Tue, 10 Nov 2026 14:18:26 +0100 Subject: [PATCH 16/24] test: keep the dot of a path segment that starts with a dot Signed-off-by: jdsika --- tests/iri_resolver/test_resolve.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/iri_resolver/test_resolve.py b/tests/iri_resolver/test_resolve.py index 10d4662bd..3ea8b4ab8 100644 --- a/tests/iri_resolver/test_resolve.py +++ b/tests/iri_resolver/test_resolve.py @@ -152,6 +152,10 @@ 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_only_scheme_slash_slash(): assert resolve('abc', 'http://') == 'http:abc' From fbfdc1a49b4aea57ecabd8c7dae506446726a47c Mon Sep 17 00:00:00 2001 From: jdsika Date: Tue, 10 Nov 2026 16:20:53 +0100 Subject: [PATCH 17/24] refactor: drop the base query in one place Signed-off-by: jdsika --- lib/pyld/iri_resolver.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/pyld/iri_resolver.py b/lib/pyld/iri_resolver.py index fe8bdd594..e3871d9ac 100644 --- a/lib/pyld/iri_resolver.py +++ b/lib/pyld/iri_resolver.py @@ -151,22 +151,19 @@ 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_iri_query_pos = base_iri.find("?") - if base_iri_query_pos > 0: - base_iri = base_iri[:base_iri_query_pos] + 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: From 593c9d27752ab28062439e95b7b3c40374600b34 Mon Sep 17 00:00:00 2001 From: jdsika Date: Tue, 10 Nov 2026 16:32:20 +0100 Subject: [PATCH 18/24] refactor: split the reference only where its path is resolved Signed-off-by: jdsika --- lib/pyld/iri_resolver.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/pyld/iri_resolver.py b/lib/pyld/iri_resolver.py index e3871d9ac..9dc631cab 100644 --- a/lib/pyld/iri_resolver.py +++ b/lib/pyld/iri_resolver.py @@ -192,12 +192,6 @@ def resolve(relative_iri: str, base_iri: str = None) -> str: if relative_iri.startswith("//"): return base_scheme + remove_dot_segments_of_path(relative_iri, value_colon_pos) - # Dot segments are only removed from the path of the value, which ends at - # the first '?' or '#' (RFC 3986, section 5.2.2) - path_end = re.search(r"[?#]|\Z", relative_iri).start() - query_and_fragment = relative_iri[path_end:] - relative_iri = relative_iri[:path_end] - # 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) @@ -209,15 +203,21 @@ def resolve(relative_iri: str, base_iri: str = None) -> str: base_slash_after_colon_pos = len(base_iri) - 1 else: return base_scheme + remove_dot_segments_of_path( - relative_iri + query_and_fragment, value_colon_pos + relative_iri, value_colon_pos ) 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 + query_and_fragment, value_colon_pos + relative_iri, value_colon_pos ) + # Dot segments are only removed from the path of the value, which ends at + # the first '?' or '#' (RFC 3986, section 5.2.2) + path_end = re.search(r"[?#]|\Z", relative_iri).start() + query_and_fragment = relative_iri[path_end:] + relative_iri = relative_iri[:path_end] + # If relative starts with '/', append after base authority if relative_iri.startswith("/"): return ( From 1d1530f229fe760318a2e92524b2d4c5460a3db8 Mon Sep 17 00:00:00 2001 From: jdsika Date: Tue, 10 Nov 2026 16:32:21 +0100 Subject: [PATCH 19/24] test: cover a root path and a first segment starting with a dot Signed-off-by: jdsika --- tests/iri_resolver/test_resolve.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/iri_resolver/test_resolve.py b/tests/iri_resolver/test_resolve.py index 3ea8b4ab8..b1b874029 100644 --- a/tests/iri_resolver/test_resolve.py +++ b/tests/iri_resolver/test_resolve.py @@ -80,6 +80,10 @@ 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' @@ -156,6 +160,13 @@ 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_base_only_scheme_slash_slash(): assert resolve('abc', 'http://') == 'http:abc' From e93f768c3fb91db0c3093940b268008914e3c95c Mon Sep 17 00:00:00 2001 From: jdsika Date: Tue, 10 Nov 2026 16:32:21 +0100 Subject: [PATCH 20/24] docs: shorten and scope the resolver changelog entry Signed-off-by: jdsika --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 538ef3794..774dad446 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,7 +33,7 @@ - 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()` ignores the base IRI's query when the reference has a path. Against a base IRI with a host, it merges the reference with `/` when the base has no path, removes dot segments from the reference's path only, not from its query or fragment, and keeps the dot of a segment such as `.gh`. For example, `/x` and `./x` against `http://example.org` gave `http://example.org//x` and `http://example.org/./x`, `x` against `http://example.org?q` gave `http://example.org?q/x`, `a/.?x` against `http://example.org/` gave `http://example.org/a?x`, and `.gh` against `http://example.org/a` gave `http://example.org/gh`. +- `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. For those references, it also no longer drops the `/` that a final `.` or `..` segment leaves before a query or fragment (`a/.?x`), or the dot of a first segment such as `.gh`. ### Changed - **BREAKING**: Developer install, command execution, documentation, and release artifact From 347b03635a2393b11bf56f0e468ff49d8378cd49 Mon Sep 17 00:00:00 2001 From: jdsika Date: Thu, 12 Nov 2026 17:25:51 +0100 Subject: [PATCH 21/24] fix: keep the slash of a final dot segment before a query or fragment remove_dot_segments() added the empty last segment after a final '/.' or '/..' only at the very end of the string, so it dropped the '/' when a '?' or '#' followed: '/abc/def/./ghi/../..#abc' gave '/abc#abc' instead of '/abc/#abc' (RFC 3986, section 5.2.4). resolve() worked around this for relative paths only, so absolute IRIs and network-path references still lost the '/' ('http://abc/def/.?x' gave 'http://abc/def?x'). Add the empty last segment whenever the dot segment is not followed by another '/'. This is the same fix as relative-to-absolute-iri.js#33. Signed-off-by: jdsika --- lib/pyld/iri_resolver.py | 10 ++++++---- tests/iri_resolver/test_remove_dot_segments.py | 18 +++++++++++++++++- tests/iri_resolver/test_resolve.py | 8 ++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/lib/pyld/iri_resolver.py b/lib/pyld/iri_resolver.py index 9dc631cab..d2416177a 100644 --- a/lib/pyld/iri_resolver.py +++ b/lib/pyld/iri_resolver.py @@ -47,8 +47,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 @@ -61,8 +62,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 diff --git a/tests/iri_resolver/test_remove_dot_segments.py b/tests/iri_resolver/test_remove_dot_segments.py index 95a33681f..7300b6451 100644 --- a/tests/iri_resolver/test_remove_dot_segments.py +++ b/tests/iri_resolver/test_remove_dot_segments.py @@ -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(): @@ -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/...' diff --git a/tests/iri_resolver/test_resolve.py b/tests/iri_resolver/test_resolve.py index b1b874029..e86cce274 100644 --- a/tests/iri_resolver/test_resolve.py +++ b/tests/iri_resolver/test_resolve.py @@ -167,6 +167,14 @@ def test_base_first_segment_starting_with_dot(): ) +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' From fe6ed5b9d9d2a4c7181339fd0762f35d21986a49 Mon Sep 17 00:00:00 2001 From: jdsika Date: Thu, 12 Nov 2026 17:26:44 +0100 Subject: [PATCH 22/24] refactor: stop splitting the reference before removing dot segments resolve() split the reference at its first '?' or '#' so that remove_dot_segments() would not drop the '/' of a final dot segment. remove_dot_segments() now keeps it, so the split is no longer needed. This changes no result. Signed-off-by: jdsika --- lib/pyld/iri_resolver.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/lib/pyld/iri_resolver.py b/lib/pyld/iri_resolver.py index d2416177a..3d6f17f10 100644 --- a/lib/pyld/iri_resolver.py +++ b/lib/pyld/iri_resolver.py @@ -7,7 +7,6 @@ .. moduleauthor:: Miel Vander Sande """ -import re from urllib.parse import ParseResult, urlparse, urlunparse @@ -214,19 +213,9 @@ def resolve(relative_iri: str, base_iri: str = None) -> str: relative_iri, value_colon_pos ) - # Dot segments are only removed from the path of the value, which ends at - # the first '?' or '#' (RFC 3986, section 5.2.2) - path_end = re.search(r"[?#]|\Z", relative_iri).start() - query_and_fragment = relative_iri[path_end:] - relative_iri = relative_iri[:path_end] - # If relative starts with '/', append after base authority if relative_iri.startswith("/"): - return ( - base_iri[:base_slash_after_colon_pos] - + remove_dot_segments(relative_iri) - + query_and_fragment - ) + return base_iri[:base_slash_after_colon_pos] + remove_dot_segments(relative_iri) base_path = base_iri[base_slash_after_colon_pos:] last_slash = base_path.rfind("/") @@ -238,7 +227,7 @@ def resolve(relative_iri: str, base_iri: str = None) -> str: relative_iri = base_path + relative_iri relative_iri = remove_dot_segments(relative_iri) - return base_iri[:base_slash_after_colon_pos] + relative_iri + query_and_fragment + return base_iri[:base_slash_after_colon_pos] + relative_iri def unresolve(absolute_iri: str, base_iri: str = ""): From a326f6957d8ff0c217e61ebd8352c2b0e96207a8 Mon Sep 17 00:00:00 2001 From: jdsika Date: Thu, 12 Nov 2026 17:26:58 +0100 Subject: [PATCH 23/24] test: cover a base IRI whose only colon is in its query Since the query of the base IRI is dropped before the scheme check, a base IRI such as 'def?x:y' has no scheme left and raises a ValueError for a path reference, as a base IRI without any ':' does. Signed-off-by: jdsika --- tests/iri_resolver/test_resolve.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/iri_resolver/test_resolve.py b/tests/iri_resolver/test_resolve.py index e86cce274..adf3a165b 100644 --- a/tests/iri_resolver/test_resolve.py +++ b/tests/iri_resolver/test_resolve.py @@ -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') From 0dcdfdc38b0dfcc42f7791d2aae0139e570db04e Mon Sep 17 00:00:00 2001 From: jdsika Date: Thu, 12 Nov 2026 17:28:04 +0100 Subject: [PATCH 24/24] docs: note the remove_dot_segments() slash fix in the changelog The fix now lives in remove_dot_segments(), so it applies to every reference, including absolute IRIs and network-path references. Signed-off-by: jdsika --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 774dad446..95122beab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,7 +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. For those references, it also no longer drops the `/` that a final `.` or `..` segment leaves before a query or fragment (`a/.?x`), or the dot of a first segment such as `.gh`. +- `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