Skip to content

validate the four hex digits of a json \u escape - #2757

Closed
netliomax25-code wants to merge 1 commit into
apache:masterfrom
netliomax25-code:json-unicode-escape-validation
Closed

validate the four hex digits of a json \u escape#2757
netliomax25-code wants to merge 1 commit into
apache:masterfrom
netliomax25-code:json-unicode-escape-validation

Conversation

@netliomax25-code

Copy link
Copy Markdown
Contributor

Repro: new JsonSlurper().parseText('{"k":"\u12"}').k returns the two-character string 12 instead of failing, and "\u+041" decodes to A; both hold for every JsonParserType, while JsonSlurperClassic rejects the same documents because JsonTokenType.STRING already validates \\u[0-9a-fA-F]{4}.
Cause: CharBuf.decodeJsonString reads the digits with Integer.parseInt(hex, 16), which accepts a leading sign and non-ASCII digits, and its index + 4 < to guard has no else branch, so a truncated escape is left unconsumed and its digits fall through the loop as text.
Fix: decode the four digits through a strict ASCII hex check and reject a short or non-hex escape the way the neighboring invalid-escape branch already does.

@paulk-asert

Copy link
Copy Markdown
Contributor

Merged as part of PR#2760. Thanks!

@paulk-asert paulk-asert closed this Aug 4, 2026
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.

2 participants