master
Kevin Wan 11 months ago committed by GitHub
parent 408827d876
commit 44d347d48a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -626,11 +626,11 @@ func (u *Unmarshaler) processFieldPrimitiveWithJSONNumber(fieldType reflect.Type
}
// if value is a pointer, we need to check overflow with the pointer's value.
overflowValidator := value
if overflowValidator.Type().Kind() == reflect.Ptr {
overflowValidator = overflowValidator.Elem()
derefedValue := value
for derefedValue.Type().Kind() == reflect.Ptr {
derefedValue = derefedValue.Elem()
}
if overflowValidator.OverflowFloat(fValue) {
if derefedValue.CanFloat() && derefedValue.OverflowFloat(fValue) {
return fmt.Errorf("parsing %q as float32: value out of range", v.String())
}

@ -1343,6 +1343,7 @@ func TestUnmarshalNullableSlice(t *testing.T) {
}
func TestUnmarshalWithFloatPtr(t *testing.T) {
t.Run("*float32", func(t *testing.T) {
var v struct {
WeightFloat32 *float32 `key:"weightFloat32,optional"`
}
@ -1353,6 +1354,20 @@ func TestUnmarshalWithFloatPtr(t *testing.T) {
if assert.NoError(t, UnmarshalKey(m, &v)) {
assert.Equal(t, float32(3.2), *v.WeightFloat32)
}
})
t.Run("**float32", func(t *testing.T) {
var v struct {
WeightFloat32 **float32 `key:"weightFloat32,optional"`
}
m := map[string]any{
"weightFloat32": json.Number("3.2"),
}
if assert.NoError(t, UnmarshalKey(m, &v)) {
assert.Equal(t, float32(3.2), **v.WeightFloat32)
}
})
}
func TestUnmarshalIntSlice(t *testing.T) {

Loading…
Cancel
Save