Fix decoding of escape char at UnmarshalJSON

This commit is contained in:
Masaaki Goshima 2021-01-30 02:03:31 +09:00
parent 73dac85d26
commit 6e154ee727
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] {
case '\\':
cursor++
continue
case '"':
literal := buf[start: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) {
dec := json.NewDecoder(strings.NewReader(`{"a": 3.14}`))
dec.UseNumber()