gin/render
Amit Mishra ed773a4d38 fix(render): encode non-BMP characters as UTF-16 surrogate pairs in AsciiJSON
AsciiJSON used fmt.Appendf with "\u%04x" to escape all non-ASCII runes.
For code points above U+FFFF the format produces a 5+ digit sequence (e.g.
ὠ0 for U+1F600), which is syntactically valid JSON but wrong: a JSON
\u escape is exactly 4 hex digits, so decoders interpret the 5th digit as
literal text and the recovered string is silently corrupted.

Per RFC 8259 section 7, code points above U+FFFF must be encoded as a
UTF-16 surrogate pair (\uD800-\uDBFF followed by \uDC00-\uDFFF). Use
unicode/utf16.EncodeRune to compute the pair and emit two \uXXXX escapes.

Add TestRenderAsciiJSONNonBMP to verify that emoji and other non-BMP
characters survive an AsciiJSON -> json.Unmarshal round-trip unchanged.

Fixes #4688

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-04 02:47:23 +05:30
..