Skip to content

Commit

Permalink
Fix parsing single quote within double quotes
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 5a9c6f7 commit 29a9673
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,7 @@ func unquoteBytes(s []byte) (t []byte, ok bool) {
if len(s) < 2 || (s[0] != '"' && s[0] != '\'') || (s[len(s)-1] != '"' && s[len(s)-1] != '\'') {
return
}
orig := s
s = s[1 : len(s)-1]

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

// Quote, control characters are invalid.
case s[0] == '"' && c == '"', s[0] == '\'' && c == '\'', c < ' ':
case orig[0] == '"' && c == '"', orig[0] == '\'' && c == '\'', c < ' ':
return

// ASCII
Expand Down
13 changes: 13 additions & 0 deletions json5_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,16 @@ func TestJSON5Decode(t *testing.T) {
return nil
})
}

// found with go-fuzz
func TestQuotedQuote(t *testing.T) {
var v struct {
E string
}
if err := Unmarshal([]byte(`{e:"'"}`), &v); err != nil {
t.Error(err)
}
if v.E != "'" {
t.Errorf(`expected "'", got %q`, v.E)
}
}

0 comments on commit 29a9673

Please sign in to comment.