summaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-02-16 19:06:46 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-02-18 22:45:54 -0700
commit00187950437a10952b82353405e5ba4b4515fb29 (patch)
tree826c4ff76310bf6f58e79f37f2107c329810aaa8 /compat
parenta87d6cbbb51a19071c5c742ef3c91bbb90a727c6 (diff)
reencode: Don't normalize the capitalization of \uXXXX hex escapes
Diffstat (limited to 'compat')
-rw-r--r--compat/json/compat.go2
-rw-r--r--compat/json/compat_test.go54
2 files changed, 34 insertions, 22 deletions
diff --git a/compat/json/compat.go b/compat/json/compat.go
index d33f278..3a9bd6c 100644
--- a/compat/json/compat.go
+++ b/compat/json/compat.go
@@ -157,7 +157,7 @@ func HTMLEscape(dst *bytes.Buffer, src []byte) {
case lowmemjson.BackslashEscapeNone:
dst.WriteRune(c)
case lowmemjson.BackslashEscapeUnicode:
- _ = jsonstring.WriteStringUnicodeEscape(dst, c)
+ _ = jsonstring.WriteStringUnicodeEscape(dst, c, mode)
default:
panic(fmt.Errorf("lowmemjson.EscapeHTMLSafe returned an unexpected escape mode=%d", mode))
}
diff --git a/compat/json/compat_test.go b/compat/json/compat_test.go
index c83ca7e..29a8b37 100644
--- a/compat/json/compat_test.go
+++ b/compat/json/compat_test.go
@@ -18,7 +18,10 @@ func TestCompatHTMLEscape(t *testing.T) {
Out string
}
testcases := map[string]testcase{
- "invalid": {In: `x`, Out: `x`},
+ "invalid": {In: `x`, Out: `x`},
+ "hex-lower": {In: `"\uabcd"`, Out: `"\uabcd"`},
+ "hex-upper": {In: `"\uABCD"`, Out: `"\uABCD"`},
+ "hex-mixed": {In: `"\uAbCd"`, Out: `"\uAbCd"`},
}
for tcName, tc := range testcases {
tc := tc
@@ -39,11 +42,14 @@ func TestCompatValid(t *testing.T) {
Exp bool
}
testcases := map[string]testcase{
- "empty": {In: ``, Exp: false},
- "num": {In: `1`, Exp: true},
- "trunc": {In: `{`, Exp: false},
- "object": {In: `{}`, Exp: true},
- "non-utf8": {In: "\"\x85\xcd\"", Exp: false}, // https://github.com/golang/go/issues/58517
+ "empty": {In: ``, Exp: false},
+ "num": {In: `1`, Exp: true},
+ "trunc": {In: `{`, Exp: false},
+ "object": {In: `{}`, Exp: true},
+ "non-utf8": {In: "\"\x85\xcd\"", Exp: false}, // https://github.com/golang/go/issues/58517
+ "hex-lower": {In: `"\uabcd"`, Exp: true},
+ "hex-upper": {In: `"\uABCD"`, Exp: true},
+ "hex-mixed": {In: `"\uAbCd"`, Exp: true},
}
for tcName, tc := range testcases {
tc := tc
@@ -64,10 +70,13 @@ func TestCompatCompact(t *testing.T) {
Err string
}
testcases := map[string]testcase{
- "trunc": {In: `{`, Out: ``, Err: `unexpected end of JSON input`},
- "object": {In: `{}`, Out: `{}`},
- "non-utf8": {In: "\"\x85\xcd\"", Out: "\"\x85\xcd\""},
- "float": {In: `1.200e003`, Out: `1.200e003`},
+ "trunc": {In: `{`, Out: ``, Err: `unexpected end of JSON input`},
+ "object": {In: `{}`, Out: `{}`},
+ "non-utf8": {In: "\"\x85\xcd\"", Out: "\"\x85\xcd\""},
+ "float": {In: `1.200e003`, Out: `1.200e003`},
+ "hex-lower": {In: `"\uabcd"`, Out: `"\uabcd"`},
+ "hex-upper": {In: `"\uABCD"`, Out: `"\uABCD"`},
+ "hex-mixed": {In: `"\uAbCd"`, Out: `"\uAbCd"`},
}
for tcName, tc := range testcases {
tc := tc
@@ -94,17 +103,20 @@ func TestCompatIndent(t *testing.T) {
Err string
}
testcases := map[string]testcase{
- "trunc": {In: `{`, Out: ``, Err: `unexpected end of JSON input`},
- "object": {In: `{}`, Out: `{}`},
- "non-utf8": {In: "\"\x85\xcd\"", Out: "\"\x85\xcd\""},
- "float": {In: `1.200e003`, Out: `1.200e003`},
- "tailws0": {In: `0`, Out: `0`},
- "tailws1": {In: `0 `, Out: `0 `},
- "tailws2": {In: `0 `, Out: `0 `},
- "tailws3": {In: "0\n", Out: "0\n"},
- "headws1": {In: ` 0`, Out: `0`},
- "objws1": {In: `{"a" : 1}`, Out: "{\n>.\"a\": 1\n>}"},
- "objws2": {In: "{\"a\"\n:\n1}", Out: "{\n>.\"a\": 1\n>}"},
+ "trunc": {In: `{`, Out: ``, Err: `unexpected end of JSON input`},
+ "object": {In: `{}`, Out: `{}`},
+ "non-utf8": {In: "\"\x85\xcd\"", Out: "\"\x85\xcd\""},
+ "float": {In: `1.200e003`, Out: `1.200e003`},
+ "tailws0": {In: `0`, Out: `0`},
+ "tailws1": {In: `0 `, Out: `0 `},
+ "tailws2": {In: `0 `, Out: `0 `},
+ "tailws3": {In: "0\n", Out: "0\n"},
+ "headws1": {In: ` 0`, Out: `0`},
+ "objws1": {In: `{"a" : 1}`, Out: "{\n>.\"a\": 1\n>}"},
+ "objws2": {In: "{\"a\"\n:\n1}", Out: "{\n>.\"a\": 1\n>}"},
+ "hex-lower": {In: `"\uabcd"`, Out: `"\uabcd"`},
+ "hex-upper": {In: `"\uABCD"`, Out: `"\uABCD"`},
+ "hex-mixed": {In: `"\uAbCd"`, Out: `"\uAbCd"`},
}
for tcName, tc := range testcases {
tc := tc