Skip to content

Commit

Permalink
Fix: Prevent panic when validating struct with nil pointer to map fie…
Browse files Browse the repository at this point in the history
…ld (#260)
  • Loading branch information
kaptinlin committed Mar 1, 2024
1 parent 9ec448d commit 1822f1e
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 1822f1e

Please sign in to comment.