diff options
author | Fede <gnufede@gmail.com> | 2018-03-23 14:11:43 +0100 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2018-03-23 09:11:43 -0400 |
commit | 6094778e697fea8daf1e4d6c4c92dec6e71999a7 (patch) | |
tree | e5bc923fa5ed5164fef9d0e2f1fe2e0af6ff1574 /model/emoji.go | |
parent | 87762ae62eb887dfb3fd0957040919aede46f7d4 (diff) | |
download | chat-6094778e697fea8daf1e4d6c4c92dec6e71999a7.tar.gz chat-6094778e697fea8daf1e4d6c4c92dec6e71999a7.tar.bz2 chat-6094778e697fea8daf1e4d6c4c92dec6e71999a7.zip |
[MM-9777] Avoids adding custom emojis with the same name as a system emoji (#8461)
* Emoji validation fails if name exists in system emojis
* Use hashmap instead of array to improve performance
* Changed utils/StringInMap to emoji/isSystemEmoji
* Load system emojis from model/emoji.json
* Added emoji.json from webapp
* Load system emojis from emoji_data.go instead of emoji.json
* Run `gofmt -w model/emoji_data.go`
Diffstat (limited to 'model/emoji.go')
-rw-r--r-- | model/emoji.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/model/emoji.go b/model/emoji.go index 47d170bb3..78a266386 100644 --- a/model/emoji.go +++ b/model/emoji.go @@ -23,6 +23,11 @@ type Emoji struct { Name string `json:"name"` } +func inSystemEmoji(emojiName string) bool { + _, ok := SystemEmojis[emojiName] + return ok +} + func (emoji *Emoji) IsValid() *AppError { if len(emoji.Id) != 26 { return NewAppError("Emoji.IsValid", "model.emoji.id.app_error", nil, "", http.StatusBadRequest) @@ -40,7 +45,7 @@ func (emoji *Emoji) IsValid() *AppError { return NewAppError("Emoji.IsValid", "model.emoji.user_id.app_error", nil, "", http.StatusBadRequest) } - if len(emoji.Name) == 0 || len(emoji.Name) > EMOJI_NAME_MAX_LENGTH || !IsValidAlphaNumHyphenUnderscore(emoji.Name, false) { + if len(emoji.Name) == 0 || len(emoji.Name) > EMOJI_NAME_MAX_LENGTH || !IsValidAlphaNumHyphenUnderscore(emoji.Name, false) || inSystemEmoji(emoji.Name) { return NewAppError("Emoji.IsValid", "model.emoji.name.app_error", nil, "", http.StatusBadRequest) } |