Skip to content

Commit

Permalink
fix: The validation of tag "options" is not working with int/uint type (
Browse files Browse the repository at this point in the history
  • Loading branch information
taobig authored Jun 5, 2022
1 parent c44edd7 commit 3fa8c59
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/mapping/unmarshaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ func (u *Unmarshaler) processFieldPrimitiveWithJSONNumber(field reflect.StructFi
return err
}

if err := validateValueInOptions(opts.options(), v); err != nil {
return err
}

if fieldKind == reflect.Ptr {
value = value.Elem()
}
Expand Down
14 changes: 14 additions & 0 deletions core/mapping/unmarshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,20 @@ func TestUnmarshalWithIntOptionsIncorrect(t *testing.T) {
assert.NotNil(t, UnmarshalKey(m, &in))
}

func TestUnmarshalWithJsonNumberOptionsIncorrect(t *testing.T) {
type inner struct {
Value string `key:"value,options=first|second"`
Incorrect int `key:"incorrect,options=1|2"`
}
m := map[string]interface{}{
"value": "first",
"incorrect": json.Number("3"),
}

var in inner
assert.NotNil(t, UnmarshalKey(m, &in))
}

func TestUnmarshalWithUintOptionsCorrect(t *testing.T) {
type inner struct {
Value string `key:"value,options=first|second"`
Expand Down

0 comments on commit 3fa8c59

Please sign in to comment.