Skip to content

Raise PointerToNowhere for non-integer array-index pointer segments - #387

Open
cognis-digital wants to merge 1 commit into
python-jsonschema:mainfrom
cognis-digital:fix/pointer-nonint-array-index
Open

Raise PointerToNowhere for non-integer array-index pointer segments#387
cognis-digital wants to merge 1 commit into
python-jsonschema:mainfrom
cognis-digital:fix/pointer-nonint-array-index

Conversation

@cognis-digital

Copy link
Copy Markdown

A JSON Pointer segment that indexes into an array but is not a valid
integer -- e.g. #/foo, #/-, or #/1x -- previously caused the
int(segment) conversion in Resource.pointer to raise a raw
ValueError, which escaped Resource.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, so PointerToNowhere is
the 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 a ValueError is turned
into PointerToNowhere(ref=pointer, resource=self), chained from the
original error. A regression test covering a non-integer segment into an
array resource is added; it fails on main and passes with this change.

The full test suite (including the referencing-suite submodule) passes,
along with ruff and mypy.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant