Fixed string length checks for fields that can contain unicode characters

Этот коммит содержится в:
hmhealey
2015-11-05 09:25:59 -05:00
родитель 2c2775e221
Коммит c016a88c84
6 изменённых файлов: 18 добавлений и 12 удалений

Просмотреть файл

@@ -6,6 +6,7 @@ package model
import (
"encoding/json"
"io"
"unicode/utf8"
)
const (
@@ -94,11 +95,11 @@ func (o *Post) IsValid() *AppError {
return NewAppError("Post.IsValid", "Invalid original id", "")
}
if len(o.Message) > 4000 {
if utf8.RuneCountInString(o.Message) > 4000 {
return NewAppError("Post.IsValid", "Invalid message", "id="+o.Id)
}
if len(o.Hashtags) > 1000 {
if utf8.RuneCountInString(o.Hashtags) > 1000 {
return NewAppError("Post.IsValid", "Invalid hashtags", "id="+o.Id)
}
@@ -106,7 +107,7 @@ func (o *Post) IsValid() *AppError {
return NewAppError("Post.IsValid", "Invalid type", "id="+o.Type)
}
if len(ArrayToJson(o.Filenames)) > 4000 {
if utf8.RuneCountInString(ArrayToJson(o.Filenames)) > 4000 {
return NewAppError("Post.IsValid", "Invalid filenames", "id="+o.Id)
}