Merge pull request #102 from goccy/feature/fix-decoding-escaped-char

Fix decoding of escape char at UnmarshalJSON
This commit is contained in:
Masaaki Goshima 2021-01-30 02:09:57 +09:00 committed by GitHub
commit c655881253
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -218,6 +218,7 @@ func (d *interfaceDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (i
switch buf[cursor] { switch buf[cursor] {
case '\\': case '\\':
cursor++ cursor++
continue
case '"': case '"':
literal := buf[start:cursor] literal := buf[start:cursor]
cursor++ cursor++

View File

@ -226,6 +226,14 @@ func Test_Decoder(t *testing.T) {
}) })
} }
func TestIssue98(t *testing.T) {
data := "[\"\\"
var v interface{}
if err := json.Unmarshal([]byte(data), &v); err == nil {
t.Fatal("expected error")
}
}
func Test_Decoder_UseNumber(t *testing.T) { func Test_Decoder_UseNumber(t *testing.T) {
dec := json.NewDecoder(strings.NewReader(`{"a": 3.14}`)) dec := json.NewDecoder(strings.NewReader(`{"a": 3.14}`))
dec.UseNumber() dec.UseNumber()