Reject unescaped control characters in JSON strings (RFC 8259)#36
Merged
Conversation
…nce) The PEG grammar accepted any character (ANY) inside strings, allowing raw control characters like newline, tab, and carriage return — all of which violate RFC 8259 §7. Changed the char rule to only allow code points U+0020 and above as unescaped characters. Escaped sequences (\n, \t, etc.) and \uXXXX escapes continue to work correctly. Added 5 new formatter tests covering rejection of unescaped control chars and acceptance of their escaped equivalents. https://claude.ai/code/session_01FHd1Nx228QwtR5sGowP7mN
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
ANY.charrule injson.pestfromANYto'\u{0020}'..'\u{10FFFF}', which excludes all control characters while still allowing the full Unicode range above U+001F.\n,\t,\r, etc.) and\uXXXXescapes continue to work correctly.Test plan
cargo testpasses with 35/35 tests green (5 new tests added)"hello\nworld"(literal newline) → parse error"hello\tworld"(literal tab) → parse error"hello\rworld"(literal CR) → parse error"hello\\nworld"(escaped\n) → accepted as-is"caf\\u00e9"(unicode escape) → accepted as-isGenerated by Claude Code