forked from mirror/go-json
Merge pull request #6 from goccy/feature/fix-null-in-string
Fix null in string type
This commit is contained in:
commit
4f06b13b6b
|
@ -135,7 +135,7 @@ func (d *stringDecoder) decodeByte(buf []byte, cursor int64) ([]byte, int64, err
|
||||||
if buf[cursor+3] != 'l' {
|
if buf[cursor+3] != 'l' {
|
||||||
return nil, 0, errInvalidCharacter(buf[cursor+3], "null", cursor)
|
return nil, 0, errInvalidCharacter(buf[cursor+3], "null", cursor)
|
||||||
}
|
}
|
||||||
cursor += 5
|
cursor += 4
|
||||||
return []byte{}, cursor, nil
|
return []byte{}, cursor, nil
|
||||||
default:
|
default:
|
||||||
goto ERROR
|
goto ERROR
|
||||||
|
|
|
@ -135,6 +135,13 @@ func Test_Decoder(t *testing.T) {
|
||||||
assertEq(t, "struct.D.AA", 2, v.D.AA)
|
assertEq(t, "struct.D.AA", 2, v.D.AA)
|
||||||
assertEq(t, "struct.D.BB", "world", v.D.BB)
|
assertEq(t, "struct.D.BB", "world", v.D.BB)
|
||||||
assertEq(t, "struct.D.CC", true, v.D.CC)
|
assertEq(t, "struct.D.CC", true, v.D.CC)
|
||||||
|
t.Run("struct.null", func(t *testing.T) {
|
||||||
|
var v struct {
|
||||||
|
A string
|
||||||
|
}
|
||||||
|
assertErr(t, json.Unmarshal([]byte(`{"a":null}`), &v))
|
||||||
|
assertEq(t, "string is null", v.A, "")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
t.Run("interface", func(t *testing.T) {
|
t.Run("interface", func(t *testing.T) {
|
||||||
t.Run("number", func(t *testing.T) {
|
t.Run("number", func(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue