Raise PointerToNowhere for non-integer array-index pointer segments - #387
Open
cognis-digital wants to merge 1 commit into
Open
Raise PointerToNowhere for non-integer array-index pointer segments#387cognis-digital wants to merge 1 commit into
cognis-digital wants to merge 1 commit into
Conversation
A JSON pointer segment that indexes into an array but is not a valid integer (e.g. /foo or /-) previously caused int() to raise a raw ValueError that escaped Resource.pointer, rather than the documented PointerToNowhere. Per RFC 6901 such a segment references a location that does not exist, so treat it the same as an out-of-range index and raise PointerToNowhere.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A JSON Pointer segment that indexes into an array but is not a valid
integer -- e.g.
#/foo,#/-, or#/1x-- previously caused theint(segment)conversion inResource.pointerto raise a rawValueError, which escapedResource.pointer/Resolver.lookup.The documented behavior (and the method's own docstring) is that a
pointer to a location that does not exist raises
PointerToNowhere.Per RFC 6901 section 4, an array reference token that is neither a valid
non-negative integer nor
-does not resolve, soPointerToNowhereisthe correct, consistent result -- the same error already raised for an
out-of-range integer index such as
#/10.The
int()conversion is now guarded so that aValueErroris turnedinto
PointerToNowhere(ref=pointer, resource=self), chained from theoriginal error. A regression test covering a non-integer segment into an
array resource is added; it fails on
mainand passes with this change.The full test suite (including the referencing-suite submodule) passes,
along with ruff and mypy.