From b622071bec9542f978e394935aa5193d056e8e1c Mon Sep 17 00:00:00 2001 From: "Kai A. Hiller" Date: Wed, 14 Feb 2024 21:14:05 +0100 Subject: [PATCH 1/2] Encode \b and \f in JSON string as themselves --- gjson.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gjson.go b/gjson.go index 7949825..4acd087 100644 --- a/gjson.go +++ b/gjson.go @@ -1926,6 +1926,10 @@ func AppendJSONString(dst []byte, s string) []byte { if s[i] < ' ' { dst = append(dst, '\\') switch s[i] { + case '\b': + dst = append(dst, 'b') + case '\f': + dst = append(dst, 'f') case '\n': dst = append(dst, 'n') case '\r': From 0f87896dc39dfae641754d3926afdfe491e2ada1 Mon Sep 17 00:00:00 2001 From: "Kai A. Hiller" Date: Wed, 14 Feb 2024 21:15:12 +0100 Subject: [PATCH 2/2] Test \b and \f JSON encoding explicitly --- gjson_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/gjson_test.go b/gjson_test.go index 247688a..5fdaf66 100644 --- a/gjson_test.go +++ b/gjson_test.go @@ -2578,6 +2578,7 @@ func TestJSONString(t *testing.T) { testJSONString(t, s) testJSONString(t, "R\xfd\xfc\a!\x82eO\x16?_\x0f\x9ab\x1dr") testJSONString(t, "_\xb9\v\xad\xb3|X!\xb6\xd9U&\xa4\x1a\x95\x04") + testJSONString(t, "\b\f") rng := rand.New(rand.NewSource(time.Now().UnixNano())) start := time.Now() var buf [16]byte