Skip to content

Commit ecd6b1c

Browse files
committed
add tests and skip string handling of escaped solidus
1 parent 0281453 commit ecd6b1c

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

decode_object_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,10 @@ func TestSkipObject(t *testing.T) {
13681368
name: "basic",
13691369
json: `"key":"value"}`,
13701370
},
1371+
{
1372+
name: "basic-escape-solidus",
1373+
json: `"key":"value\/solidus"}`,
1374+
},
13711375
{
13721376
name: "basic-escaped",
13731377
json: `"key":"value\\\\\\\" hello"}`,

decode_string.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (dec *Decoder) parseEscapedString() error {
8888
default:
8989
return dec.raiseInvalidJSONErr(dec.cursor)
9090
}
91-
// Truncate the previous backslash character, and the
91+
9292
dec.data = append(dec.data[:dec.cursor-1], dec.data[dec.cursor:]...)
9393
dec.length--
9494

@@ -138,7 +138,7 @@ func (dec *Decoder) skipEscapedString() error {
138138
return dec.raiseInvalidJSONErr(dec.cursor)
139139
}
140140
return nil
141-
case 'n', 'r', 't':
141+
case 'n', 'r', 't', '/', 'f', 'b':
142142
return nil
143143
default:
144144
// nSlash must be even

decode_string_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ func TestDecoderString(t *testing.T) {
2323
expectedResult: "string",
2424
err: false,
2525
},
26+
{
27+
name: "string-solidus",
28+
json: `"\/"`,
29+
expectedResult: "/",
30+
err: false,
31+
},
2632
{
2733
name: "basic-string",
2834
json: ``,
@@ -403,6 +409,12 @@ func TestSkipString(t *testing.T) {
403409
err: true,
404410
errType: InvalidJSONError(""),
405411
},
412+
{
413+
name: "string-solidus",
414+
json: `Asia\/Bangkok","enable":true}"`,
415+
expectedResult: "",
416+
err: false,
417+
},
406418
}
407419

408420
for _, testCase := range testCases {

0 commit comments

Comments
 (0)