Skip to content

fix(json): use two-char short forms \b and \f in JSON.stringify (#5047)#5048

Merged
proggeramlug merged 1 commit into
mainfrom
fix/json-stringify-short-escapes
Jun 13, 2026
Merged

fix(json): use two-char short forms \b and \f in JSON.stringify (#5047)#5048
proggeramlug merged 1 commit into
mainfrom
fix/json-stringify-short-escapes

Conversation

@proggeramlug

Copy link
Copy Markdown
Contributor

Fixes #5047.

Problem

QuoteJSONString (ECMA-262 §25.5.2.2) defines two-character escapes for backspace (U+0008) and formfeed (U+000C). Perry used the short forms for tab/newline/CR but fell back to the generic 4-hex-digit \uXXXX escape for \b and \f. Both parse back identically, but it breaks byte-for-byte parity with Node and snapshot tests.

Fix

Add 0x08 → \\b and 0x0c → \\f to the escape table in json/stringify.rs (single escape site). Other control characters (e.g. U+000B) keep the \uXXXX form, per spec.

Validation

  • New unit test stringify_uses_two_char_short_forms_for_backspace_and_formfeed (also pins that U+000B keeps the hex form); full json:: test module passes (14/14).
  • End-to-end: compiled the issue repro — Perry output now matches Node byte-for-byte:
    "a\fb\bc"
    "x\u000by"
    

Code-only PR per the external-metadata convention — version bump + changelog left for merge time.

QuoteJSONString (ECMA-262) defines two-character escapes for backspace
(U+0008) and formfeed (U+000C); Perry emitted the generic 4-hex-digit
unicode escape for both, breaking byte-for-byte parity with Node and
snapshot tests. Tab/newline/CR already used the short forms.

Other control characters (e.g. U+000B) keep the \uXXXX form, matching
the spec.
@proggeramlug proggeramlug merged commit 553a9da into main Jun 13, 2026
13 checks passed
@proggeramlug proggeramlug deleted the fix/json-stringify-short-escapes branch June 13, 2026 04:18
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.

JSON.stringify emits \u000c/\u0008 instead of the \f/\b short forms

1 participant