Skip to content

Commit 186e4d1

Browse files
committed
Also strip empty fragments when using __getiem__ on Registries.
1 parent 57cdd6e commit 186e4d1

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

docs/changes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
Changelog
33
=========
44

5+
v0.27.3
6+
-------
7+
8+
* Also strip fragments when using ``__getitem__`` on URIs with empty fragments.
9+
510
v0.27.2
611
-------
712

referencing/_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def __getitem__(self, uri: URI) -> Resource[D]:
241241
Return the (already crawled) `Resource` identified by the given URI.
242242
"""
243243
try:
244-
return self._resources[uri]
244+
return self._resources[uri.rstrip("#")]
245245
except KeyError:
246246
raise exceptions.NoSuchResource(ref=uri)
247247

referencing/tests/test_core.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,21 @@ def test_contents(self):
155155
registry = Registry().with_resource(uri, resource)
156156
assert registry.contents(uri) == {"foo": "bar"}
157157

158+
def test_getitem_strips_empty_fragments(self):
159+
uri = "http://example.com/"
160+
resource = ID_AND_CHILDREN.create_resource({"ID": uri + "#"})
161+
registry = resource @ Registry()
162+
assert registry[uri] == registry[uri + "#"] == resource
163+
158164
def test_contents_strips_empty_fragments(self):
159165
uri = "http://example.com/"
160166
resource = ID_AND_CHILDREN.create_resource({"ID": uri + "#"})
161167
registry = resource @ Registry()
162-
assert registry.contents(uri) == {"ID": uri + "#"}
168+
assert (
169+
registry.contents(uri)
170+
== registry.contents(uri + "#")
171+
== {"ID": uri + "#"}
172+
)
163173

164174
def test_crawled_anchor(self):
165175
resource = ID_AND_CHILDREN.create_resource({"anchors": {"foo": "bar"}})

0 commit comments

Comments
 (0)