mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 16:30:55 +00:00
fix MinSize / MaxSize / Length should use Rune Count
This commit is contained in:
parent
d043ebcdd3
commit
83e6079ff7
@ -5,6 +5,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"time"
|
"time"
|
||||||
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
|
||||||
var MessageTmpls = map[string]string{
|
var MessageTmpls = map[string]string{
|
||||||
@ -158,7 +159,7 @@ type MinSize struct {
|
|||||||
|
|
||||||
func (m MinSize) IsSatisfied(obj interface{}) bool {
|
func (m MinSize) IsSatisfied(obj interface{}) bool {
|
||||||
if str, ok := obj.(string); ok {
|
if str, ok := obj.(string); ok {
|
||||||
return len(str) >= m.Min
|
return utf8.RuneCountInString(str) >= m.Min
|
||||||
}
|
}
|
||||||
v := reflect.ValueOf(obj)
|
v := reflect.ValueOf(obj)
|
||||||
if v.Kind() == reflect.Slice {
|
if v.Kind() == reflect.Slice {
|
||||||
@ -187,7 +188,7 @@ type MaxSize struct {
|
|||||||
|
|
||||||
func (m MaxSize) IsSatisfied(obj interface{}) bool {
|
func (m MaxSize) IsSatisfied(obj interface{}) bool {
|
||||||
if str, ok := obj.(string); ok {
|
if str, ok := obj.(string); ok {
|
||||||
return len(str) <= m.Max
|
return utf8.RuneCountInString(str) <= m.Max
|
||||||
}
|
}
|
||||||
v := reflect.ValueOf(obj)
|
v := reflect.ValueOf(obj)
|
||||||
if v.Kind() == reflect.Slice {
|
if v.Kind() == reflect.Slice {
|
||||||
@ -216,7 +217,7 @@ type Length struct {
|
|||||||
|
|
||||||
func (l Length) IsSatisfied(obj interface{}) bool {
|
func (l Length) IsSatisfied(obj interface{}) bool {
|
||||||
if str, ok := obj.(string); ok {
|
if str, ok := obj.(string); ok {
|
||||||
return len(str) == l.N
|
return utf8.RuneCountInString(str) == l.N
|
||||||
}
|
}
|
||||||
v := reflect.ValueOf(obj)
|
v := reflect.ValueOf(obj)
|
||||||
if v.Kind() == reflect.Slice {
|
if v.Kind() == reflect.Slice {
|
||||||
|
Loading…
Reference in New Issue
Block a user