gin/render
Sarthak Srivastav 25173ee381 fix(render): correctly escape non-BMP Unicode in AsciiJSON
AsciiJSON escaped every non-ASCII rune with "\u%04x", which only yields a
valid escape for the Basic Multilingual Plane (U+0000-U+FFFF). For a code
point above U+FFFF such as U+1F600 it emitted six hex digits ("ὠ0").
A JSON parser reads \u as exactly four hex digits, so this decoded to "ὠ0"
instead of "😀".

Per RFC 8259, code points above U+FFFF must be encoded as a UTF-16
surrogate pair (two \uXXXX escapes). Detect r > 0xFFFF and emit the pair via
unicode/utf16.EncodeRune. ASCII and BMP output is unchanged.

Add a regression test asserting AsciiJSON output is ASCII-only and
round-trips back to the original value.

Fixes #4688

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-03 18:54:55 +05:30
..