Skip to content

Commit

Permalink
fix issue #1921
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn committed Aug 24, 2022
1 parent e9b8e39 commit 6f7f526
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
7 changes: 6 additions & 1 deletion util/gvalid/gvalid_validator_check_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,13 @@ func (v *Validator) doCheckValueRecursively(ctx context.Context, in doCheckValue
// Ignore data, assoc, rules and messages from parent.
var (
validator = v.Clone()
toBeValidatedObject = reflect.New(in.Type).Interface()
toBeValidatedObject interface{}
)
if in.Type.Kind() == reflect.Ptr {
toBeValidatedObject = reflect.New(in.Type.Elem()).Interface()
} else {
toBeValidatedObject = reflect.New(in.Type).Interface()
}
validator.assoc = nil
validator.rules = nil
validator.messages = nil
Expand Down
22 changes: 22 additions & 0 deletions util/gvalid/gvalid_z_unit_feature_recursive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,25 @@ func Test_Issue1983(t *testing.T) {
t.AssertNil(err)
})
}

// https://github.com/gogf/gf/issues/1921
func Test_Issue1921(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
type SearchOption struct {
Size int `v:"max:100"`
}
type SearchReq struct {
Option *SearchOption `json:"option,omitempty"`
}

var (
req = SearchReq{
Option: &SearchOption{
Size: 10000,
},
}
)
err := g.Validator().Data(req).Run(ctx)
t.Assert(err, "The Size value `10000` must be equal or lesser than 100")
})
}

0 comments on commit 6f7f526

Please sign in to comment.