8000 Fix: Prevent panic when validating struct with nil pointer to map field by kaptinlin · Pull Request #260 · gookit/validate · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix: Prevent panic when validating struct with nil pointer to map field #260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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