Skip to content

Reject unescaped control characters in JSON strings (RFC 8259)#36

Merged
vbergae merged 1 commit into
mainfrom
fix/reject-control-chars-in-strings
May 16, 2026
Merged

Reject unescaped control characters in JSON strings (RFC 8259)#36
vbergae merged 1 commit into
mainfrom
fix/reject-control-chars-in-strings

Conversation

@vbergae

@vbergae vbergae commented May 16, 2026

Copy link
Copy Markdown
Owner

Summary

  • RFC 8259 §7 prohibits unescaped control characters (U+0000–U+001F) inside JSON strings, but the PEG grammar accepted them via ANY.
  • Changed the char rule in json.pest from ANY to '\u{0020}'..'\u{10FFFF}', which excludes all control characters while still allowing the full Unicode range above U+001F.
  • Escaped sequences (\n, \t, \r, etc.) and \uXXXX escapes continue to work correctly.

Test plan

  • cargo test passes 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-is

Generated by Claude Code

…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
@vbergae vbergae merged commit 7bd4f7e into main May 16, 2026
9 checks passed
@vbergae vbergae deleted the fix/reject-control-chars-in-strings branch May 16, 2026 21:28
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