fix: issue 3840 (#3845)
This commit is contained in:
@@ -625,7 +625,12 @@ func (u *Unmarshaler) processFieldPrimitiveWithJSONNumber(fieldType reflect.Type
|
||||
return err
|
||||
}
|
||||
|
||||
if value.OverflowFloat(fValue) {
|
||||
// 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()
|
||||
}
|
||||
if overflowValidator.OverflowFloat(fValue) {
|
||||
return fmt.Errorf("parsing %q as float32: value out of range", v.String())
|
||||
}
|
||||
|
||||
|
||||
@@ -1339,8 +1339,20 @@ func TestUnmarshalNullableSlice(t *testing.T) {
|
||||
"slice": `[null,2]`,
|
||||
}
|
||||
|
||||
ast := assert.New(t)
|
||||
ast.Equal(UnmarshalKey(m, &v), errNilSliceElement)
|
||||
assert.New(t).Equal(UnmarshalKey(m, &v), errNilSliceElement)
|
||||
}
|
||||
|
||||
func TestUnmarshalWithFloatPtr(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) {
|
||||
|
||||
Reference in New Issue
Block a user