Skip to content

fix: escape raw control characters in strings - #67

Merged
dsherret merged 1 commit into
mainfrom
fix/escape-control-chars-in-strings
Sep 14, 2026
Merged

dsherret merged 1 commit into
mainfrom
fix/escape-control-chars-in-strings

Conversation

@dsherret

Copy link
Copy Markdown
Member

Closes #63

JSON strings can't contain raw control characters (U+0000 through U+001F), but the parser accepts them. The formatter passed them straight to the printer, so a raw newline or tab caused a panic in debug builds and invalid JSON in release builds.

String literals now have these characters escaped. \n, \r, \t, \b and \f get their short forms and everything else becomes \u00XX. This covers single-quoted strings and property names too.

Existing escape sequences are left as they are. The parser rejects a backslash followed by a raw control character, so escaping can't change what a string means.

Raw tabs and lone CRs inside strings will now show up as \t/\r in files that previously formatted without changes.

@dsherret
dsherret merged commit 307ac7b into main Sep 14, 2026
2 checks passed
@dsherret
dsherret deleted the fix/escape-control-chars-in-strings branch September 14, 2026 03:03
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.

Debug panic printing JSON strings that contain raw control characters

1 participant