summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--json5_test.go11
-rw-r--r--scanner.go2
2 files changed, 11 insertions, 2 deletions
diff --git a/json5_test.go b/json5_test.go
index 7f0bbcb..4e8eeb1 100644
--- a/json5_test.go
+++ b/json5_test.go
@@ -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
@@ -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)
+ }
+}
diff --git a/scanner.go b/scanner.go
index b5d1715..283459a 100644
--- a/scanner.go
+++ b/scanner.go
@@ -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)