summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhmhealey <harrisonmhealey@gmail.com>2015-11-05 09:25:59 -0500
committerhmhealey <harrisonmhealey@gmail.com>2015-11-05 09:35:35 -0500
commitc016a88c845ecaa4d219de43243efe07f0103c2d (patch)
tree9e3ab5b68b3c42c17f75450971401ab5a4ca1f44
parent2c2775e22179942ff30bbabd9cc864012fee5fb5 (diff)
downloadchat-c016a88c845ecaa4d219de43243efe07f0103c2d.tar.gz
chat-c016a88c845ecaa4d219de43243efe07f0103c2d.tar.bz2
chat-c016a88c845ecaa4d219de43243efe07f0103c2d.zip
Fixed string length checks for fields that can contain unicode characters
-rw-r--r--model/channel.go7
-rw-r--r--model/oauth.go3
-rw-r--r--model/post.go7
-rw-r--r--model/preference.go3
-rw-r--r--model/team.go3
-rw-r--r--model/user.go7
6 files changed, 18 insertions, 12 deletions
diff --git a/model/channel.go b/model/channel.go
index ac54a7e44..0ce09f4bc 100644
--- a/model/channel.go
+++ b/model/channel.go
@@ -6,6 +6,7 @@ package model
import (
"encoding/json"
"io"
+ "unicode/utf8"
)
const (
@@ -74,7 +75,7 @@ func (o *Channel) IsValid() *AppError {
return NewAppError("Channel.IsValid", "Update at must be a valid time", "id="+o.Id)
}
- if len(o.DisplayName) > 64 {
+ if utf8.RuneCountInString(o.DisplayName) > 64 {
return NewAppError("Channel.IsValid", "Invalid display name", "id="+o.Id)
}
@@ -90,11 +91,11 @@ func (o *Channel) IsValid() *AppError {
return NewAppError("Channel.IsValid", "Invalid type", "id="+o.Id)
}
- if len(o.Header) > 1024 {
+ if utf8.RuneCountInString(o.Header) > 1024 {
return NewAppError("Channel.IsValid", "Invalid header", "id="+o.Id)
}
- if len(o.Purpose) > 128 {
+ if utf8.RuneCountInString(o.Purpose) > 128 {
return NewAppError("Channel.IsValid", "Invalid purpose", "id="+o.Id)
}
diff --git a/model/oauth.go b/model/oauth.go
index 0320e7ec7..67825dd97 100644
--- a/model/oauth.go
+++ b/model/oauth.go
@@ -7,6 +7,7 @@ import (
"encoding/json"
"fmt"
"io"
+ "unicode/utf8"
)
type OAuthApp struct {
@@ -57,7 +58,7 @@ func (a *OAuthApp) IsValid() *AppError {
return NewAppError("OAuthApp.IsValid", "Invalid homepage", "app_id="+a.Id)
}
- if len(a.Description) > 512 {
+ if utf8.RuneCountInString(a.Description) > 512 {
return NewAppError("OAuthApp.IsValid", "Invalid description", "app_id="+a.Id)
}
diff --git a/model/post.go b/model/post.go
index 11f3ad0d5..e0074b348 100644
--- a/model/post.go
+++ b/model/post.go
@@ -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)
}
diff --git a/model/preference.go b/model/preference.go
index 44279f71a..bcd0237f1 100644
--- a/model/preference.go
+++ b/model/preference.go
@@ -6,6 +6,7 @@ package model
import (
"encoding/json"
"io"
+ "unicode/utf8"
)
const (
@@ -52,7 +53,7 @@ func (o *Preference) IsValid() *AppError {
return NewAppError("Preference.IsValid", "Invalid name", "name="+o.Name)
}
- if len(o.Value) > 128 {
+ if utf8.RuneCountInString(o.Value) > 128 {
return NewAppError("Preference.IsValid", "Value is too long", "value="+o.Value)
}
diff --git a/model/team.go b/model/team.go
index 5c9cf5a26..e7dde4766 100644
--- a/model/team.go
+++ b/model/team.go
@@ -9,6 +9,7 @@ import (
"io"
"regexp"
"strings"
+ "unicode/utf8"
)
const (
@@ -122,7 +123,7 @@ func (o *Team) IsValid(restrictTeamNames bool) *AppError {
return NewAppError("Team.IsValid", "Invalid email", "id="+o.Id)
}
- if len(o.DisplayName) == 0 || len(o.DisplayName) > 64 {
+ if utf8.RuneCountInString(o.DisplayName) == 0 || utf8.RuneCountInString(o.DisplayName) > 64 {
return NewAppError("Team.IsValid", "Invalid name", "id="+o.Id)
}
diff --git a/model/user.go b/model/user.go
index 15016f8dc..871d1bf2d 100644
--- a/model/user.go
+++ b/model/user.go
@@ -10,6 +10,7 @@ import (
"io"
"regexp"
"strings"
+ "unicode/utf8"
)
const (
@@ -80,15 +81,15 @@ func (u *User) IsValid() *AppError {
return NewAppError("User.IsValid", "Invalid email", "user_id="+u.Id)
}
- if len(u.Nickname) > 64 {
+ if utf8.RuneCountInString(u.Nickname) > 64 {
return NewAppError("User.IsValid", "Invalid nickname", "user_id="+u.Id)
}
- if len(u.FirstName) > 64 {
+ if utf8.RuneCountInString(u.FirstName) > 64 {
return NewAppError("User.IsValid", "Invalid first name", "user_id="+u.Id)
}
- if len(u.LastName) > 64 {
+ if utf8.RuneCountInString(u.LastName) > 64 {
return NewAppError("User.IsValid", "Invalid last name", "user_id="+u.Id)
}