test: add test for non-BMP characters in AsciiJSON

This commit is contained in:
Md Mushfiqur Rahim 2026-06-25 00:32:47 +00:00 committed by GitHub
parent 0657c32bd3
commit d0c2793bec

View File

@ -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)