a002f784 by astaxie

Merge pull request #1097 from pylemon/develop

form required validate for bool field bugfix
2 parents cdf9ff40 caa260f0
...@@ -26,6 +26,12 @@ func TestRequired(t *testing.T) { ...@@ -26,6 +26,12 @@ func TestRequired(t *testing.T) {
26 if valid.Required(nil, "nil").Ok { 26 if valid.Required(nil, "nil").Ok {
27 t.Error("nil object should be false") 27 t.Error("nil object should be false")
28 } 28 }
29 if !valid.Required(true, "bool").Ok {
30 t.Error("Bool value should always return true")
31 }
32 if !valid.Required(false, "bool").Ok {
33 t.Error("Bool value should always return true")
34 }
29 if valid.Required("", "string").Ok { 35 if valid.Required("", "string").Ok {
30 t.Error("\"'\" string should be false") 36 t.Error("\"'\" string should be false")
31 } 37 }
......
...@@ -64,8 +64,8 @@ func (r Required) IsSatisfied(obj interface{}) bool { ...@@ -64,8 +64,8 @@ func (r Required) IsSatisfied(obj interface{}) bool {
64 if str, ok := obj.(string); ok { 64 if str, ok := obj.(string); ok {
65 return len(str) > 0 65 return len(str) > 0
66 } 66 }
67 if b, ok := obj.(bool); ok { 67 if _, ok := obj.(bool); ok {
68 return b 68 return true
69 } 69 }
70 if i, ok := obj.(int); ok { 70 if i, ok := obj.(int); ok {
71 return i != 0 71 return i != 0
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!