1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-23 01:30:56 +00:00

Merge pull request #1097 from pylemon/develop

form required validate for bool field bugfix
This commit is contained in:
astaxie 2015-03-27 23:04:07 +08:00
commit a002f78443
2 changed files with 8 additions and 2 deletions

View File

@ -26,6 +26,12 @@ func TestRequired(t *testing.T) {
if valid.Required(nil, "nil").Ok { if valid.Required(nil, "nil").Ok {
t.Error("nil object should be false") t.Error("nil object should be false")
} }
if !valid.Required(true, "bool").Ok {
t.Error("Bool value should always return true")
}
if !valid.Required(false, "bool").Ok {
t.Error("Bool value should always return true")
}
if valid.Required("", "string").Ok { if valid.Required("", "string").Ok {
t.Error("\"'\" string should be false") t.Error("\"'\" string should be false")
} }

View File

@ -64,8 +64,8 @@ func (r Required) IsSatisfied(obj interface{}) bool {
if str, ok := obj.(string); ok { if str, ok := obj.(string); ok {
return len(str) > 0 return len(str) > 0
} }
if b, ok := obj.(bool); ok { if _, ok := obj.(bool); ok {
return b return true
} }
if i, ok := obj.(int); ok { if i, ok := obj.(int); ok {
return i != 0 return i != 0