Skip to content

Commit

Permalink
Fix Type called on zero reflect.Value (#1156)
Browse files Browse the repository at this point in the history
Fixes #1155

Simply added back the check for invalid reflect types before calling
`Type` on `reflect.Value`.
  • Loading branch information
MysteriousPotato authored Aug 30, 2023
1 parent 1b40ba0 commit 75eeb3f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ func (v *validate) traverseField(ctx context.Context, parent reflect.Value, curr
}
}

if kind == reflect.Invalid {
return
}

case reflect.Struct:
isNestedStruct = !current.Type().ConvertibleTo(timeType)
// For backward compatibility before struct level validation tags were supported
Expand Down
7 changes: 7 additions & 0 deletions validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2317,6 +2317,13 @@ func TestSQLValueValidation(t *testing.T) {
Equal(t, len(errs.(ValidationErrors)), 2)
AssertError(t, errs, "CustomMadeUpStruct.MadeUp", "CustomMadeUpStruct.MadeUp", "MadeUp", "MadeUp", "required")
AssertError(t, errs, "CustomMadeUpStruct.OverriddenInt", "CustomMadeUpStruct.OverriddenInt", "OverriddenInt", "OverriddenInt", "gt")

// Test for empty field on structs without tags
type InvalidValuePanicSafetyTest struct {
V valuer
}
errs = validate.Struct(InvalidValuePanicSafetyTest{})
Equal(t, errs, nil)
}

func TestMACValidation(t *testing.T) {
Expand Down

0 comments on commit 75eeb3f

Please sign in to comment.