Result is wrong while there are multiple group of OR operators #910 (#911)

pull/936/head
XIE Long 3 years ago committed by GitHub
parent f2d3ff7f98
commit af72f63d39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      validator.go
  2. 24
      validator_test.go

@ -355,6 +355,10 @@ OUTER:
v.ct = ct v.ct = ct
if ct.fn(ctx, v) { if ct.fn(ctx, v) {
if ct.isBlockEnd {
ct = ct.next
continue OUTER
}
// drain rest of the 'or' values, then continue or leave // drain rest of the 'or' values, then continue or leave
for { for {
@ -368,6 +372,11 @@ OUTER:
if ct.typeof != typeOr { if ct.typeof != typeOr {
continue OUTER continue OUTER
} }
if ct.isBlockEnd {
ct = ct.next
continue OUTER
}
} }
} }

@ -11790,3 +11790,27 @@ func TestCreditCardFormatValidation(t *testing.T) {
} }
} }
} }
func TestMultiOrOperatorGroup(t *testing.T) {
tests := []struct {
Value int `validate:"eq=1|gte=5,eq=1|lt=7"`
expected bool
}{
{1, true}, {2, false}, {5, true}, {6, true}, {8, false},
}
validate := New()
for i, test := range tests {
errs := validate.Struct(test)
if test.expected {
if !IsEqual(errs, nil) {
t.Fatalf("Index: %d multi_group_of_OR_operators failed Error: %s", i, errs)
}
} else {
if IsEqual(errs, nil) {
t.Fatalf("Index: %d multi_group_of_OR_operators should have errs", i)
}
}
}
}

Loading…
Cancel
Save