Skip to content

Commit

Permalink
🐛 fix: reflect: call of reflect.Value.IsNil on array Value. see #280
Browse files Browse the repository at this point in the history
- perf: skip parse on slice/array elements is simple kind
  • Loading branch information
inhere committed Dec 21, 2024
1 parent d0e50a8 commit ced4035
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,11 @@ func (d *StructData) parseRulesFromTag(v *Validation) {
fValue = removeValuePtr(fValue)

// Check if the reflect.Value is valid and not a nil pointer
if !fValue.IsValid() || fValue.IsNil() {
if !fValue.IsValid() || (ft.Kind() == reflect.Slice && fValue.IsNil()) {
continue
}
// perf: skip parse on elements is simple kind
if reflects.IsSimpleKind(ft.Elem().Kind()) {
continue
}

Expand Down
11 changes: 11 additions & 0 deletions issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1775,3 +1775,14 @@ func TestIssues_276(t *testing.T) {
fmt.Println(v.Errors.OneError()) // returns a random error
fmt.Println(v.Errors.Field("Age")) // returns error messages of the field
}

// https://github.com/gookit/validate/issues/280
func TestIssues_280(t *testing.T) {
type TestData struct {
ID mockUUID
}

data := TestData{}
v := validate.New(data)
assert.Nil(t, v.ValidateErr())
}

0 comments on commit ced4035

Please sign in to comment.