Merge pull request #657 from nigelis/bugfix/omitempty-not-first

Validate tag omitempty, only base on field value
pull/671/head
Dean Karn 4 years ago committed by GitHub
commit 2a5412a1bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      validator.go
  2. 10
      validator_test.go

@ -249,7 +249,7 @@ OUTER:
v.cf = cf v.cf = cf
v.ct = ct v.ct = ct
if !v.fldIsPointer && !hasValue(v) { if !hasValue(v) {
return return
} }

@ -9265,6 +9265,16 @@ func TestRequiredWithout(t *testing.T) {
AssertError(t, errs, "Field6", "Field6", "Field6", "Field6", "required_without") AssertError(t, errs, "Field6", "Field6", "Field6", "Field6", "required_without")
AssertError(t, errs, "Field7", "Field7", "Field7", "Field7", "required_without") AssertError(t, errs, "Field7", "Field7", "Field7", "Field7", "required_without")
AssertError(t, errs, "Field8", "Field8", "Field8", "Field8", "required_without") AssertError(t, errs, "Field8", "Field8", "Field8", "Field8", "required_without")
test3 := struct {
Field1 *string `validate:"required_without=Field2,omitempty,min=1" json:"field_1"`
Field2 *string `validate:"required_without=Field1,omitempty,min=1" json:"field_2"`
}{
Field1: &fieldVal,
}
errs = validate.Struct(&test3)
Equal(t, errs, nil)
} }
func TestRequiredWithoutAll(t *testing.T) { func TestRequiredWithoutAll(t *testing.T) {

Loading…
Cancel
Save