Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
83e6079f
authored
2013-10-16 22:49:06 +0800
by
slene
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix MinSize / MaxSize / Length should use Rune Count
1 parent
d043ebcd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
3 deletions
validation/validators.go
validation/validators.go
View file @
83e6079
...
...
@@ -5,6 +5,7 @@ import (
"reflect"
"regexp"
"time"
"unicode/utf8"
)
var
MessageTmpls
=
map
[
string
]
string
{
...
...
@@ -158,7 +159,7 @@ type MinSize struct {
func
(
m
MinSize
)
IsSatisfied
(
obj
interface
{})
bool
{
if
str
,
ok
:=
obj
.
(
string
);
ok
{
return
len
(
str
)
>=
m
.
Min
return
utf8
.
RuneCountInString
(
str
)
>=
m
.
Min
}
v
:=
reflect
.
ValueOf
(
obj
)
if
v
.
Kind
()
==
reflect
.
Slice
{
...
...
@@ -187,7 +188,7 @@ type MaxSize struct {
func
(
m
MaxSize
)
IsSatisfied
(
obj
interface
{})
bool
{
if
str
,
ok
:=
obj
.
(
string
);
ok
{
return
len
(
str
)
<=
m
.
Max
return
utf8
.
RuneCountInString
(
str
)
<=
m
.
Max
}
v
:=
reflect
.
ValueOf
(
obj
)
if
v
.
Kind
()
==
reflect
.
Slice
{
...
...
@@ -216,7 +217,7 @@ type Length struct {
func
(
l
Length
)
IsSatisfied
(
obj
interface
{})
bool
{
if
str
,
ok
:=
obj
.
(
string
);
ok
{
return
len
(
str
)
==
l
.
N
return
utf8
.
RuneCountInString
(
str
)
==
l
.
N
}
v
:=
reflect
.
ValueOf
(
obj
)
if
v
.
Kind
()
==
reflect
.
Slice
{
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment