Skip to content

fix(scripts): encode residual JSON control chars as \uXXXX instead of stripping#1872

Open
pierluigilenoci wants to merge 1 commit intogithub:mainfrom
pierluigilenoci:fix/json-escape-uxxxx-encoding
Open

fix(scripts): encode residual JSON control chars as \uXXXX instead of stripping#1872
pierluigilenoci wants to merge 1 commit intogithub:mainfrom
pierluigilenoci:fix/json-escape-uxxxx-encoding

Conversation

@pierluigilenoci
Copy link
Contributor

Summary

  • json_escape() in common.sh was silently deleting control characters (U+0000–U+001F) not individually handled (\n, \t, \r, \b, \f) via tr -d, causing data loss
  • Per RFC 8259, these characters must be encoded as \uXXXX sequences
  • Replaced the tr -d strip with a char-by-char loop that emits proper \uXXXX escapes, preserving data integrity
  • Multi-byte UTF-8 sequences are unaffected (first-byte values >= 0xC0 are never control characters)

Example

Before: "hello\x01world""helloworld" (SOH silently deleted)
After: "hello\x01world""hello\u0001world" (SOH properly escaped)

Test plan

  • Verify json_escape correctly encodes control characters like SOH (\x01), STX (\x02), etc. as \uXXXX
  • Verify previously handled characters (\n, \t, \r, \b, \f) still use their short escape forms
  • Verify multi-byte UTF-8 strings (e.g. emoji, CJK) pass through unchanged
  • Run check-prerequisites.sh --json and create-new-feature.sh --json to verify JSON output is valid

…pping

json_escape() was silently deleting control characters (U+0000-U+001F)
that were not individually handled (\n, \t, \r, \b, \f). Per RFC 8259,
these must be encoded as \uXXXX sequences to preserve data integrity.

Replace the tr -d strip with a char-by-char loop that emits proper
\uXXXX escapes for any remaining control characters.
@pierluigilenoci pierluigilenoci requested a review from mnriem as a code owner March 16, 2026 23:37
@pierluigilenoci
Copy link
Contributor Author

@mnriem @dhilipkumars, please take a look.

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.

1 participant