-
-
Notifications
You must be signed in to change notification settings - Fork 272
Description
The current json-pointer format tests already cover most common syntax and escape rules.
However, a few valid constructs explicitly permitted by RFC 6901 mentioned in spec are not currently tested.
RFC 6901 references
Unicode support
Section 3 states: A JSON Pointer is a Unicode string
The ABNF defines: unescaped = %x00-2E / %x30-7D / %x7F-10FFFF
The %x7F-10FFFF range explicitly allows all non-ASCII Unicode characters (e.g., accented letters, symbols, emoji).
Therefore, pointers must not be limited to ASCII-only characters.
Control characters allowed after JSON unescaping
From Section 3: unescaped = %x00-2E
This includes control characters (%x00–%x1F).
Section 5 additionally states: control (%x00-1F) characters MUST be escaped
This means they must be escaped in JSON string encoding, but are still valid pointer characters once unescaped.
Validators should therefore accept pointers containing characters like NUL, newline, or tab.
Empty reference tokens are valid
The grammar defines:
json-pointer = *( "/" reference-token )
reference-token = *( unescaped / escaped )
Because * allows zero-length tokens, empty segments are valid.
Examples that must be syntactically valid:
//////
Escape ordering edge case (~01)
Section 4 specifies escape processing order:
first transforming '~1' to '/', and then transforming '~0' to '~' avoids the error of turning '~01' first into '~1' and then into '/'
The RFC explicitly discusses ~01, meaning this edge case is intentional and must be handled correctly.
Proposed tests to add
[
{
"description": "valid JSON-pointer (Unicode characters allowed by RFC 6901)",
"data": "/foo/bar/😎",
"valid": true
},
{
"description": "valid JSON-pointer (control characters allowed after JSON unescaping)",
"data": "/foo\u0000bar\n\tbaz",
"valid": true
},
{
"description": "valid JSON-pointer (only empty reference tokens)",
"data": "///",
"valid": true
},
{
"description": "valid JSON-pointer (escape ordering edge case ~01)",
"data": "/~01",
"valid": true
}
]If this approach looks good, I’m happy to open a PR with these additions.