mirror of
https://github.com/gin-gonic/gin.git
synced 2026-09-04 22:53:34 +08:00
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>