fix(json): reject backtick as hex digit in \u escapes#3678
Draft
tonyfettes wants to merge 1 commit into
Draft
Conversation
The hex letter branch of lex_hex_digits case-folds with `c & ~32` and only checks the upper bound `d > 15`. Backtick (0x60) folds to '@' (0x40), yielding d == 9, so it slipped through as hex digit 9: the invalid JSON `"\u`bcd"` parsed successfully as U+9BCD instead of raising ParseError. It is the only character in the codespace with this property; add the missing lower-bound check `d < 10`. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Summary
@json.parseaccepts backtick as hex digit 9 in\uXXXXescapes: the invalid JSON"\ubcd"parses successfully to"\u{9BCD}"("鯍") instead of raisingParseError`.The hex letter branch of
ParseContext::lex_hex_digitscase-folds withc & ~32and then only checks the upper bound:Backtick (0x60) folds to
'@'(0x40), yieldingd == 9, which passesd > 15. It is the only character in the codespace with this property (0x41–0x5F fold to themselves; of 0x60–0x7F only 0x60 lands below'A'after folding). Fix: also rejectd < 10, since every valid letter digit folds into 10–15.Changes
json/lex_string.mbt: add the missing lower-bound check (d < 10 || d > 15) with a comment explaining the backtick case.json/lex_string_test.mbt: regression tests —\u`bcd,\u@bcd,\u1G23,\u1g23now raiseInvalidChar, and boundary digits (0/9/a/f/A/F) still parse.No public API change (
pkg.generated.mbtiuntouched).Testing
moon test json— 174/174 passingmoon fmt/moon info— clean🤖 Generated with Claude Code