mirror of
https://github.com/json-iterator/go.git
synced 2025-02-19 19:59:49 +02:00
fix #243 fuzzy decoder should take null as valid input
This commit is contained in:
parent
fff342fd04
commit
ad83167dc6
@ -183,6 +183,9 @@ func (decoder *fuzzyStringDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Ite
|
||||
*((*string)(ptr)) = string(number)
|
||||
case jsoniter.StringValue:
|
||||
*((*string)(ptr)) = iter.ReadString()
|
||||
case jsoniter.NilValue:
|
||||
iter.Skip()
|
||||
*((*string)(ptr)) = ""
|
||||
default:
|
||||
iter.ReportError("fuzzyStringDecoder", "not number or string")
|
||||
}
|
||||
@ -208,6 +211,9 @@ func (decoder *fuzzyIntegerDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.It
|
||||
} else {
|
||||
str = "0"
|
||||
}
|
||||
case jsoniter.NilValue:
|
||||
iter.Skip()
|
||||
str = "0"
|
||||
default:
|
||||
iter.ReportError("fuzzyIntegerDecoder", "not number or string")
|
||||
}
|
||||
@ -244,6 +250,9 @@ func (decoder *fuzzyFloat32Decoder) Decode(ptr unsafe.Pointer, iter *jsoniter.It
|
||||
} else {
|
||||
*((*float32)(ptr)) = 0
|
||||
}
|
||||
case jsoniter.NilValue:
|
||||
iter.Skip()
|
||||
*((*float32)(ptr)) = 0
|
||||
default:
|
||||
iter.ReportError("fuzzyFloat32Decoder", "not number or string")
|
||||
}
|
||||
@ -273,7 +282,10 @@ func (decoder *fuzzyFloat64Decoder) Decode(ptr unsafe.Pointer, iter *jsoniter.It
|
||||
} else {
|
||||
*((*float64)(ptr)) = 0
|
||||
}
|
||||
case jsoniter.NilValue:
|
||||
iter.Skip()
|
||||
*((*float64)(ptr)) = 0
|
||||
default:
|
||||
iter.ReportError("fuzzyFloat32Decoder", "not number or string")
|
||||
iter.ReportError("fuzzyFloat64Decoder", "not number or string")
|
||||
}
|
||||
}
|
||||
|
@ -357,3 +357,35 @@ func Test_bad_case(t *testing.T) {
|
||||
should := require.New(t)
|
||||
should.Nil(err)
|
||||
}
|
||||
|
||||
func Test_null_to_string(t *testing.T) {
|
||||
should := require.New(t)
|
||||
body := []byte(`null`)
|
||||
var message string
|
||||
err := jsoniter.Unmarshal(body, &message)
|
||||
should.NoError(err)
|
||||
}
|
||||
|
||||
func Test_null_to_int(t *testing.T) {
|
||||
should := require.New(t)
|
||||
body := []byte(`null`)
|
||||
var message int
|
||||
err := jsoniter.Unmarshal(body, &message)
|
||||
should.NoError(err)
|
||||
}
|
||||
|
||||
func Test_null_to_float32(t *testing.T) {
|
||||
should := require.New(t)
|
||||
body := []byte(`null`)
|
||||
var message float32
|
||||
err := jsoniter.Unmarshal(body, &message)
|
||||
should.NoError(err)
|
||||
}
|
||||
|
||||
func Test_null_to_float64(t *testing.T) {
|
||||
should := require.New(t)
|
||||
body := []byte(`null`)
|
||||
var message float64
|
||||
err := jsoniter.Unmarshal(body, &message)
|
||||
should.NoError(err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user