Skip to content

fix: resolve references against a base without a path as RFC 3986 does - #2

Open
jdsika wants to merge 24 commits into
masterfrom
fix/iri-resolve-base-without-path
Open

jdsika wants to merge 24 commits into
masterfrom
fix/iri-resolve-base-without-path

Conversation

@jdsika

@jdsika jdsika commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Mirror of digitalbazaar#372, which has the description, the reproducer and the review.

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Coverage

Coverage Report
FileStmtsMissCoverMissing
lib/pyld
   canon.py2901296%36, 47, 51, 55, 85–86, 530, 552, 616, 626, 680–681
   context_resolver.py103892%78, 137, 151, 197, 203–205, 229
   iri_resolver.py140398%308–309, 319
   jsonld.py251316394%252–256, 305, 342, 347, 357, 374–389, 425–426, 468, 476, 496, 504–505, 613–618, 701–702, 717–718, 781–786, 811–812, 827–828, 838–839, 865, 913, 927–928, 951–952, 994, 1001, 1008, 1076, 1101, 1123–1125, 1135–1138, 1153, 1176, 1188–1191, 1287, 1296–1299, 1319, 1348, 1381, 1385, 1419, 1436–1438, 1448–1450, 1493, 1512–1515, 1528, 1577, 1680–1687, 1714–1716, 1742–1745, 1921, 1959, 2265, 2396, 2405–2412, 2506, 2533, 2557, 2565, 3159, 3209, 3228, 3293, 3346, 3349, 3412, 3497, 3531, 3818, 3823, 3825, 4020–4022, 4165, 4228, 4467, 4755, 4887, 4921, 4950–4953, 4975–4976, 5159, 5223, 5250, 5324, 5326, 5344, 5442, 5491, 5723, 5725, 5764, 5766, 5775, 5917, 6045, 6132, 6252–6266, 6400, 6666, 6672–6676, 6715, 6718, 6808–6809, 6818
   util.py72396%43, 116, 136
lib/pyld/cli
   app.py44295%77, 80
   entry.py12375%9–11, 24
   input.py52198%57
lib/pyld/documentloader
   aiohttp.py712269%29–39, 68, 74, 86, 98–106, 118–121, 138, 153–156
   file.py36197%49
   requests.py52590%57, 71, 83–91
   requests_sqlite_cache.py25196%19
   scheme_directed.py15193%38
   type_directed.py15193%41
TOTAL379622694% 

Tests Skipped Failures Errors Time
1977 28 💤 0 ❌ 0 🔥 2m 30s ⏱️

Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
…a path

Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
… a path

Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
…its query or fragment

Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
… query tests

Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
Signed-off-by: jdsika <carlo.van-driesten@vdl.digital>
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 <carlo.van-driesten@vdl.digital>
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 <carlo.van-driesten@vdl.digital>
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 <carlo.van-driesten@vdl.digital>
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 <carlo.van-driesten@vdl.digital>
@jdsika
jdsika force-pushed the fix/iri-resolve-base-without-path branch from d167f6e to 0dcdfdc Compare November 13, 2026 08:52

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant