summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
Diffstat (limited to 'model')
-rw-r--r--model/reaction.go5
-rw-r--r--model/reaction_test.go25
2 files changed, 19 insertions, 11 deletions
diff --git a/model/reaction.go b/model/reaction.go
index 5dbf07152..3d334c214 100644
--- a/model/reaction.go
+++ b/model/reaction.go
@@ -6,6 +6,7 @@ package model
import (
"encoding/json"
"io"
+ "regexp"
)
type Reaction struct {
@@ -60,7 +61,9 @@ func (o *Reaction) IsValid() *AppError {
return NewLocAppError("Reaction.IsValid", "model.reaction.is_valid.post_id.app_error", nil, "post_id="+o.PostId)
}
- if len(o.EmojiName) == 0 || len(o.EmojiName) > 64 || !IsValidAlphaNumHyphenUnderscore(o.EmojiName, false) {
+ validName := regexp.MustCompile(`^[a-zA-Z0-9\-\+_]+$`)
+
+ if len(o.EmojiName) == 0 || len(o.EmojiName) > 64 || !validName.MatchString(o.EmojiName) {
return NewLocAppError("Reaction.IsValid", "model.reaction.is_valid.emoji_name.app_error", nil, "emoji_name="+o.EmojiName)
}
diff --git a/model/reaction_test.go b/model/reaction_test.go
index e447e4329..a35750477 100644
--- a/model/reaction_test.go
+++ b/model/reaction_test.go
@@ -42,16 +42,6 @@ func TestReactionIsValid(t *testing.T) {
}
reaction.PostId = NewId()
- reaction.EmojiName = ""
- if err := reaction.IsValid(); err == nil {
- t.Fatal("emoji name should be invalid")
- }
-
- reaction.EmojiName = strings.Repeat("a", 65)
- if err := reaction.IsValid(); err == nil {
- t.Fatal("emoji name should be invalid")
- }
-
reaction.EmojiName = strings.Repeat("a", 64)
if err := reaction.IsValid(); err != nil {
t.Fatal(err)
@@ -67,11 +57,26 @@ func TestReactionIsValid(t *testing.T) {
t.Fatal(err)
}
+ reaction.EmojiName = "+1"
+ if err := reaction.IsValid(); err != nil {
+ t.Fatal(err)
+ }
+
reaction.EmojiName = "emoji:"
if err := reaction.IsValid(); err == nil {
t.Fatal(err)
}
+ reaction.EmojiName = ""
+ if err := reaction.IsValid(); err == nil {
+ t.Fatal("emoji name should be invalid")
+ }
+
+ reaction.EmojiName = strings.Repeat("a", 65)
+ if err := reaction.IsValid(); err == nil {
+ t.Fatal("emoji name should be invalid")
+ }
+
reaction.CreateAt = 0
if err := reaction.IsValid(); err == nil {
t.Fatal("create at should be invalid")