Skip to content

Commit

Permalink
fix: Prevent panic on validating nil pointer to slice field (#252) (#253
Browse files Browse the repository at this point in the history
)
  • Loading branch information
kaptinlin committed Jan 3, 2024
1 parent cf7f910 commit 117b816
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,11 @@ func (d *StructData) parseRulesFromTag(v *Validation) {

case reflect.Array, reflect.Slice:
fValue = removeValuePtr(fValue)

// Check if the reflect.Value is valid and not a nil pointer
if !fValue.IsValid() || (fValue.Kind() == reflect.Ptr && fValue.IsNil()) {
continue
}
for j := 0; j < fValue.Len(); j++ {
elemValue := removeValuePtr(fValue.Index(j))
elemType := removeTypePtr(elemValue.Type())
Expand Down

0 comments on commit 117b816

Please sign in to comment.