Skip to content

Commit 75eeb3f

Browse files
Fix Type called on zero reflect.Value (#1156)
Fixes #1155 Simply added back the check for invalid reflect types before calling `Type` on `reflect.Value`.
1 parent 1b40ba0 commit 75eeb3f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

validator.go

+4
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ func (v *validate) traverseField(ctx context.Context, parent reflect.Value, curr
162162
}
163163
}
164164

165+
if kind == reflect.Invalid {
166+
return
167+
}
168+
165169
case reflect.Struct:
166170
isNestedStruct = !current.Type().ConvertibleTo(timeType)
167171
// For backward compatibility before struct level validation tags were supported

validator_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -2317,6 +2317,13 @@ func TestSQLValueValidation(t *testing.T) {
23172317
Equal(t, len(errs.(ValidationErrors)), 2)
23182318
AssertError(t, errs, "CustomMadeUpStruct.MadeUp", "CustomMadeUpStruct.MadeUp", "MadeUp", "MadeUp", "required")
23192319
AssertError(t, errs, "CustomMadeUpStruct.OverriddenInt", "CustomMadeUpStruct.OverriddenInt", "OverriddenInt", "OverriddenInt", "gt")
2320+
2321+
// Test for empty field on structs without tags
2322+
type InvalidValuePanicSafetyTest struct {
2323+
V valuer
2324+
}
2325+
errs = validate.Struct(InvalidValuePanicSafetyTest{})
2326+
Equal(t, errs, nil)
23202327
}
23212328

23222329
func TestMACValidation(t *testing.T) {

0 commit comments

Comments
 (0)