Skip to content

Commit ced4035

Browse files
committed
🐛 fix: reflect: call of reflect.Value.IsNil on array Value. see #280
- perf: skip parse on slice/array elements is simple kind
1 parent d0e50a8 commit ced4035

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

data_source.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,11 @@ func (d *StructData) parseRulesFromTag(v *Validation) {
384384
fValue = removeValuePtr(fValue)
385385

386386
// Check if the reflect.Value is valid and not a nil pointer
387-
if !fValue.IsValid() || fValue.IsNil() {
387+
if !fValue.IsValid() || (ft.Kind() == reflect.Slice && fValue.IsNil()) {
388+
continue
389+
}
390+
// perf: skip parse on elements is simple kind
391+
if reflects.IsSimpleKind(ft.Elem().Kind()) {
388392
continue
389393
}
390394

issues_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,3 +1775,14 @@ func TestIssues_276(t *testing.T) {
17751775
fmt.Println(v.Errors.OneError()) // returns a random error
17761776
fmt.Println(v.Errors.Field("Age")) // returns error messages of the field
17771777
}
1778+
1779+
// https://github.com/gookit/validate/issues/280
1780+
func TestIssues_280(t *testing.T) {
1781+
type TestData struct {
1782+
ID mockUUID
1783+
}
1784+
1785+
data := TestData{}
1786+
v := validate.New(data)
1787+
assert.Nil(t, v.ValidateErr())
1788+
}

0 commit comments

Comments
 (0)