Skip to content

Commit

Permalink
Fix escaped carriage return parsing
Browse files Browse the repository at this point in the history
Found with go-fuzz

Signed-off-by: Jonathan Rudenberg <jonathan@titanous.com>
  • Loading branch information
titanous committed Jul 17, 2016
1 parent 29a9673 commit 7620272
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion json5_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ func TestJSON5Decode(t *testing.T) {
})
}

// found with go-fuzz
// The tests below this comment were found with go-fuzz

func TestQuotedQuote(t *testing.T) {
var v struct {
E string
Expand All @@ -143,3 +144,11 @@ func TestQuotedQuote(t *testing.T) {
t.Errorf(`expected "'", got %q`, v.E)
}
}

func TestInvalidNewline(t *testing.T) {
expected := "invalid character '\\n' in string literal"
var v interface{}
if err := Unmarshal([]byte("{a:'\\\r0\n'}"), &v); err == nil || err.Error() != expected {
t.Errorf("expected error %q, got %s", expected, err)
}
}
2 changes: 1 addition & 1 deletion scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,8 @@ func stateInStringEsc(resume func(s *scanner, c byte) int) func(s *scanner, c by
// stateInStringEscCR is the state after reading `"\\r` during a quoted string.
func stateInStringEscCR(resume func(s *scanner, c byte) int) func(s *scanner, c byte) int {
return func(s *scanner, c byte) int {
s.step = resume
if c == '\n' {
s.step = resume
return scanContinue
}
return resume(s, c)
Expand Down

0 comments on commit 7620272

Please sign in to comment.