mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 13:40:55 +00:00
Merge pull request #2365 from chesedo/RequiredValidationCatchSpaces
[WIP]Have Required validator trim strings to fix #2361
This commit is contained in:
commit
388a5610fa
@ -35,6 +35,12 @@ func TestRequired(t *testing.T) {
|
|||||||
if valid.Required("", "string").Ok {
|
if valid.Required("", "string").Ok {
|
||||||
t.Error("\"'\" string should be false")
|
t.Error("\"'\" string should be false")
|
||||||
}
|
}
|
||||||
|
if valid.Required(" ", "string").Ok {
|
||||||
|
t.Error("\" \" string should be false") // For #2361
|
||||||
|
}
|
||||||
|
if valid.Required("\n", "string").Ok {
|
||||||
|
t.Error("new line string should be false") // For #2361
|
||||||
|
}
|
||||||
if !valid.Required("astaxie", "string").Ok {
|
if !valid.Required("astaxie", "string").Ok {
|
||||||
t.Error("string should be true")
|
t.Error("string should be true")
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
@ -98,7 +99,7 @@ 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(strings.TrimSpace(str)) > 0
|
||||||
}
|
}
|
||||||
if _, ok := obj.(bool); ok {
|
if _, ok := obj.(bool); ok {
|
||||||
return true
|
return true
|
||||||
|
Loading…
Reference in New Issue
Block a user