Skip to content

Commit 7620272

Browse files
committed
Fix escaped carriage return parsing
Found with go-fuzz Signed-off-by: Jonathan Rudenberg <[email protected]>
1 parent 29a9673 commit 7620272

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

json5_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ func TestJSON5Decode(t *testing.T) {
131131
})
132132
}
133133

134-
// found with go-fuzz
134+
// The tests below this comment were found with go-fuzz
135+
135136
func TestQuotedQuote(t *testing.T) {
136137
var v struct {
137138
E string
@@ -143,3 +144,11 @@ func TestQuotedQuote(t *testing.T) {
143144
t.Errorf(`expected "'", got %q`, v.E)
144145
}
145146
}
147+
148+
func TestInvalidNewline(t *testing.T) {
149+
expected := "invalid character '\\n' in string literal"
150+
var v interface{}
151+
if err := Unmarshal([]byte("{a:'\\\r0\n'}"), &v); err == nil || err.Error() != expected {
152+
t.Errorf("expected error %q, got %s", expected, err)
153+
}
154+
}

scanner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,8 @@ func stateInStringEsc(resume func(s *scanner, c byte) int) func(s *scanner, c by
500500
// stateInStringEscCR is the state after reading `"\\r` during a quoted string.
501501
func stateInStringEscCR(resume func(s *scanner, c byte) int) func(s *scanner, c byte) int {
502502
return func(s *scanner, c byte) int {
503+
s.step = resume
503504
if c == '\n' {
504-
s.step = resume
505505
return scanContinue
506506
}
507507
return resume(s, c)

0 commit comments

Comments
 (0)