Skip to content

Commit e008282

Browse files
committed
Notice when we change base URIs while indexing into a document.
Passes a few additional tests.
1 parent 56b09b8 commit e008282

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

referencing/_core.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,10 @@ def lookup(self, ref: str) -> tuple[Schema, Resolver]:
156156
uri, fragment = self._base_uri, ref[1:]
157157
else:
158158
uri, fragment = urldefrag(urljoin(self._base_uri, ref))
159+
159160
target, registry = self._registry.resource_at(uri)
161+
base_uri = uri
162+
160163
if fragment.startswith("/"):
161164
segments = unquote(fragment[1:]).split("/")
162165
for segment in segments:
@@ -165,15 +168,23 @@ def lookup(self, ref: str) -> tuple[Schema, Resolver]:
165168
else:
166169
segment = segment.replace("~1", "/").replace("~0", "~")
167170
target = target[segment] # type: ignore # this can't be a bool
171+
# FIXME: this is wrong, we need to know that we are crossing
172+
# the boundary of a *schema* specifically
173+
if not isinstance(target, Sequence):
174+
id = self._registry._specification.id_of(target)
175+
if id is not None:
176+
base_uri = urljoin(base_uri, id).rstrip("#")
168177
elif fragment:
169178
anchor = registry.anchors_at(uri=uri)[fragment]
170179
target, uri = anchor.resolve(resolver=self, uri=uri)
171180

172-
id = self._registry._specification.id_of(target)
173-
if id is not None:
174-
base_uri = urljoin(self._base_uri, id).rstrip("#")
181+
id = self._registry._specification.id_of(target)
182+
if id is not None:
183+
base_uri = urljoin(self._base_uri, id).rstrip("#")
175184
else:
176-
base_uri = uri
185+
id = self._registry._specification.id_of(target)
186+
if id is not None:
187+
base_uri = urljoin(self._base_uri, id).rstrip("#")
177188
return target, self.evolve(base_uri=base_uri, registry=registry)
178189

179190
def with_root(self, root) -> Resolver:

0 commit comments

Comments
 (0)