Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
388a5610
Commit
388a5610
authored
May 18, 2017
by
astaxie
Committed by
GitHub
May 18, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2365 from chesedo/RequiredValidationCatchSpaces
[WIP]Have Required validator trim strings to fix #2361
parents
41498758
a8a2dffc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
1 deletion
+8
-1
validation_test.go
validation/validation_test.go
+6
-0
validators.go
validation/validators.go
+2
-1
No files found.
validation/validation_test.go
View file @
388a5610
...
...
@@ -35,6 +35,12 @@ func TestRequired(t *testing.T) {
if
valid
.
Required
(
""
,
"string"
)
.
Ok
{
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
{
t
.
Error
(
"string should be true"
)
}
...
...
validation/validators.go
View file @
388a5610
...
...
@@ -18,6 +18,7 @@ import (
"fmt"
"reflect"
"regexp"
"strings"
"time"
"unicode/utf8"
)
...
...
@@ -98,7 +99,7 @@ func (r Required) IsSatisfied(obj interface{}) bool {
}
if
str
,
ok
:=
obj
.
(
string
);
ok
{
return
len
(
str
)
>
0
return
len
(
str
ings
.
TrimSpace
(
str
)
)
>
0
}
if
_
,
ok
:=
obj
.
(
bool
);
ok
{
return
true
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment