mirror of
https://github.com/gin-gonic/gin.git
synced 2026-09-04 14:49:27 +08:00
test: add test for non-BMP characters in AsciiJSON
This commit is contained in:
parent
0657c32bd3
commit
d0c2793bec
@ -1263,6 +1263,18 @@ func TestContextRenderNoContentSecureJSON(t *testing.T) {
|
||||
assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))
|
||||
}
|
||||
|
||||
func TestContextAsciiJSONNonBMP(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
c, _ := CreateTestContext(w)
|
||||
|
||||
// Non-BMP characters (emoji) should be encoded as UTF-16 surrogate pairs
|
||||
c.AsciiJSON(http.StatusOK, H{"emoji": "😀"})
|
||||
|
||||
assert.Equal(t, http.StatusOK, w.Code)
|
||||
assert.Equal(t, "{\"emoji\":\"\\ud83d\\ude00\"}", w.Body.String())
|
||||
assert.Equal(t, "application/json", w.Header().Get("Content-Type"))
|
||||
}
|
||||
|
||||
func TestContextRenderNoContentAsciiJSON(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
c, _ := CreateTestContext(w)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user