Repository navigation
Conversation
RFC 6901 section 3 lets a reference token contain any character except '/' and '~' (escaped as ~0 and ~1), so "/a#b" is a valid JSON Pointer. The json-pointer and relative-json-pointer patterns also excluded '#', so format assertions rejected such pointers. Only the URI fragment representation (section 6) starts with '#', and that form is still rejected because a JSON Pointer must start with '/'.
Review of #1394Reviewed at head Since this PR rewrites both patterns, two older problems in them are worth fixing here too, plus a CHANGELOG line. Older problems in the same patterns1. A long reference token throws With format assertions on, validating Suggested fix: use possessive groups, as Use the same token part inside 2. The 2020-12 validation spec references draft-bhutton-relative-json-pointer-00. Its grammar is Allowing Minor
|
With format assertions on, a long reference token, such as "/" followed by 5,000 characters as json-pointer or "0/" followed by them as relative-json-pointer, made validation throw StackOverflowError: the regex engine recursed once per character on the token group. Both patterns now share one JSON Pointer sub-pattern with possessive groups, as uri-template already uses. A token can be split into characters and ~0/~1 escapes only one way, so the possessive form accepts the same values; a 100,000-character token now validates.
Draft 2020-12 references draft-bhutton-relative-json-pointer-00, whose
origin-specification may end with an index manipulation,
("+" / "-") positive-integer, so 0+1/foo and 1-1# are valid there. The
earlier drafts reference draft-handrews-relative-json-pointer, which has
no index manipulation.
The format list is shared by all dialects, so relative-json-pointer is
now a RelativeJsonPointerFormat that reads the specification version from
the schema context, like BaseFormatValidator does, and allows the index
manipulation only for 2020-12. +1/foo/bar, -1/foo/bar, 0+0 and 0-01 stay
invalid, and nothing changes for draft 4 to 2019-09.
Re-review of #1394Reviewed at head
MinorThe |
The
json-pointerandrelative-json-pointerformat patterns exclude#from reference tokens ([^/#~]), so format assertions reject valid JSON Pointers such as/a#b.RFC 6901 section 3 defines a reference token as
*( unescaped / escaped )withunescaped = %x00-2E / %x30-7D / %x7F-10FFFF. That excludes only/(0x2F) and~(0x7E), so#(0x23) is an ordinary character in a token. Only the URI fragment identifier representation (section 6) begins with#, and that form is not a JSON Pointer string. The JSON-Schema-Test-Suite cases#,#/and#aare still rejected, because a JSON Pointer must start with/.json-pointer/a#bjson-pointer/#json-pointer/foo#bar/bazrelative-json-pointer0/a#brelative-json-pointer2/#json-pointer#/a,a#b,/a~2#relative-json-pointer/a#b,01/a,0##The fix removes
#from the excluded characters in both patterns ([^/#~]→[^/~]), and nothing else changes. The0#form ofrelative-json-pointeris unaffected.JsonPointerFormatTestchecks both formats through a schema with format assertions enabled. Its 7 cases with#inside a token fail without the change, and the reject cases pass before and after.The full build (
mvn --batch-mode verify, as in CI) passes:The
2.xbranch has the same two patterns (Formats.javalines 75–76) if a backport is wanted.The change and the tests were prepared with an AI assistant (Claude Code with Claude Opus 5.5).
I used an AI assistant to help prepare this change.