Skip to content

Commit

Permalink
Also strip empty fragments when using __getiem__ on Registries.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Apr 24, 2023
1 parent 57cdd6e commit 186e4d1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Changelog
=========

v0.27.3
-------

* Also strip fragments when using ``__getitem__`` on URIs with empty fragments.

v0.27.2
-------

Expand Down
2 changes: 1 addition & 1 deletion referencing/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def __getitem__(self, uri: URI) -> Resource[D]:
Return the (already crawled) `Resource` identified by the given URI.
"""
try:
return self._resources[uri]
return self._resources[uri.rstrip("#")]
except KeyError:
raise exceptions.NoSuchResource(ref=uri)

Expand Down
12 changes: 11 additions & 1 deletion referencing/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,21 @@ def test_contents(self):
registry = Registry().with_resource(uri, resource)
assert registry.contents(uri) == {"foo": "bar"}

def test_getitem_strips_empty_fragments(self):
uri = "http://example.com/"
resource = ID_AND_CHILDREN.create_resource({"ID": uri + "#"})
registry = resource @ Registry()
assert registry[uri] == registry[uri + "#"] == resource

def test_contents_strips_empty_fragments(self):
uri = "http://example.com/"
resource = ID_AND_CHILDREN.create_resource({"ID": uri + "#"})
registry = resource @ Registry()
assert registry.contents(uri) == {"ID": uri + "#"}
assert (
registry.contents(uri)
== registry.contents(uri + "#")
== {"ID": uri + "#"}
)

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

0 comments on commit 186e4d1

Please sign in to comment.