Skip to content

Commit

Permalink
fix: Prevent panic on validating nil pointer to slice and map fields
Browse files Browse the repository at this point in the history
  • Loading branch information
kaptinlin committed Mar 1, 2024
1 parent 9ec448d commit 25a1e9c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func (d *StructData) parseRulesFromTag(v *Validation) {
fValue = removeValuePtr(fValue)

// Check if the reflect.Value is valid and not a nil pointer
if !fValue.IsValid() {
if !fValue.IsValid() || fValue.IsNil() {
continue
}

Expand All @@ -400,6 +400,12 @@ func (d *StructData) parseRulesFromTag(v *Validation) {

case reflect.Map:
fValue = removeValuePtr(fValue)

// Check if the reflect.Value is valid and not a nil pointer
if !fValue.IsValid() || fValue.IsNil() {
continue
}

for _, key := range fValue.MapKeys() {
key = removeValuePtr(key)
elemValue := removeValuePtr(fValue.MapIndex(key))
Expand Down

0 comments on commit 25a1e9c

Please sign in to comment.