Skip to content

Commit 29a9673

Browse files
committed
Fix parsing single quote within double quotes
Found with go-fuzz Signed-off-by: Jonathan Rudenberg <[email protected]>
1 parent 5a9c6f7 commit 29a9673

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

decode.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,7 @@ func unquoteBytes(s []byte) (t []byte, ok bool) {
11891189
if len(s) < 2 || (s[0] != '"' && s[0] != '\'') || (s[len(s)-1] != '"' && s[len(s)-1] != '\'') {
11901190
return
11911191
}
1192+
orig := s
11921193
s = s[1 : len(s)-1]
11931194

11941195
// Check for unusual characters. If there are none,
@@ -1287,7 +1288,7 @@ func unquoteBytes(s []byte) (t []byte, ok bool) {
12871288
}
12881289

12891290
// Quote, control characters are invalid.
1290-
case s[0] == '"' && c == '"', s[0] == '\'' && c == '\'', c < ' ':
1291+
case orig[0] == '"' && c == '"', orig[0] == '\'' && c == '\'', c < ' ':
12911292
return
12921293

12931294
// ASCII

json5_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,16 @@ func TestJSON5Decode(t *testing.T) {
130130
return nil
131131
})
132132
}
133+
134+
// found with go-fuzz
135+
func TestQuotedQuote(t *testing.T) {
136+
var v struct {
137+
E string
138+
}
139+
if err := Unmarshal([]byte(`{e:"'"}`), &v); err != nil {
140+
t.Error(err)
141+
}
142+
if v.E != "'" {
143+
t.Errorf(`expected "'", got %q`, v.E)
144+
}
145+
}

0 commit comments

Comments
 (0)