From d0c2793becbd2f065b1a4942fb346b09fb855a37 Mon Sep 17 00:00:00 2001 From: Md Mushfiqur Rahim <20mahin2020@gmail.com> Date: Thu, 25 Jun 2026 00:32:47 +0000 Subject: [PATCH] test: add test for non-BMP characters in AsciiJSON --- context_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/context_test.go b/context_test.go index 2dfdd392..11ca9ede 100644 --- a/context_test.go +++ b/context_test.go @@ -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)