Skip to content

Commit b39ebf9

Browse files
committed
Yet another stab at anchor lookup from non-canonical URIs.
This fixes looking up anchors in a subresource which changes the base URI (e.g. the location-independent identifier with base URI change tests in the official suite). Refs: f520b40
1 parent 90e977c commit b39ebf9

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

docs/changes.rst

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
Changelog
33
=========
44

5+
v0.27.2
6+
-------
7+
8+
* Another fix for looking up anchors from non-canonical URIs, now when they're inside a subresource which has a relative ``$id``.
9+
510
v0.27.1
611
-------
712

referencing/_core.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -364,20 +364,23 @@ def anchor(self, uri: URI, name: str):
364364
"""
365365
Retrieve a given anchor from a resource which must already be crawled.
366366
"""
367-
resource = self.get(uri)
368-
if resource is None:
369-
canonical_uri = uri
370-
else:
371-
canonical_uri = resource.id() or uri
372-
373-
value = self._anchors.get((canonical_uri, name))
367+
value = self._anchors.get((uri, name))
374368
if value is not None:
375369
return Retrieved(value=value, registry=self)
376370

377371
registry = self.crawl()
378-
value = registry._anchors.get((canonical_uri, name))
372+
value = registry._anchors.get((uri, name))
379373
if value is not None:
380374
return Retrieved(value=value, registry=registry)
375+
376+
resource = self.get(uri)
377+
if resource is not None:
378+
canonical_uri = resource.id()
379+
if canonical_uri is not None:
380+
value = registry._anchors.get((canonical_uri, name))
381+
if value is not None:
382+
return Retrieved(value=value, registry=registry)
383+
381384
if "/" in name:
382385
raise exceptions.InvalidAnchor(
383386
ref=uri,

0 commit comments

Comments
 (0)