[MM-36481] Fix emoji regex to support thumbsup (#17846)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ec8aaec5ce
Коммит
f8fc5190ee
@@ -81,7 +81,7 @@ func GetCustomStatus(message string) *model.CustomStatus {
|
|||||||
Text: message,
|
Text: message,
|
||||||
}
|
}
|
||||||
|
|
||||||
firstEmojiLocations := model.ALL_EMOJI_PATTERN.FindIndex([]byte(message))
|
firstEmojiLocations := model.EMOJI_PATTERN.FindIndex([]byte(message))
|
||||||
if len(firstEmojiLocations) > 0 && firstEmojiLocations[0] == 0 {
|
if len(firstEmojiLocations) > 0 && firstEmojiLocations[0] == 0 {
|
||||||
// emoji found at starting index
|
// emoji found at starting index
|
||||||
customStatus.Emoji = message[firstEmojiLocations[0]+1 : firstEmojiLocations[1]-1]
|
customStatus.Emoji = message[firstEmojiLocations[0]+1 : firstEmojiLocations[1]-1]
|
||||||
|
|||||||
@@ -16,13 +16,7 @@ const (
|
|||||||
EMOJI_SORT_BY_NAME = "name"
|
EMOJI_SORT_BY_NAME = "name"
|
||||||
)
|
)
|
||||||
|
|
||||||
var EMOJI_PATTERN = regexp.MustCompile(`:[a-zA-Z0-9_-]+:`)
|
var EMOJI_PATTERN = regexp.MustCompile(`:[a-zA-Z0-9_+-]+:`)
|
||||||
|
|
||||||
// ALL_EMOJI_PATTERN is same as the EMOJI_PATTERN except for allowing a '+' character.
|
|
||||||
// This is to allow the system emoji :+1: to be matched.
|
|
||||||
// We kept a separate variable to avoid renaming help texts for custom emoji's.
|
|
||||||
// TODO: Merge ALL_EMOJI_PATTERN with EMOJI_PATTERN after updating custom emoji help texts
|
|
||||||
var ALL_EMOJI_PATTERN = regexp.MustCompile(`:[a-zA-Z0-9_+-]+:`)
|
|
||||||
|
|
||||||
var ReverseSystemEmojisMap = makeReverseEmojiMap()
|
var ReverseSystemEmojisMap = makeReverseEmojiMap()
|
||||||
|
|
||||||
@@ -86,7 +80,7 @@ func (emoji *Emoji) IsValid() *AppError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IsValidEmojiName(name string) *AppError {
|
func IsValidEmojiName(name string) *AppError {
|
||||||
if name == "" || len(name) > EMOJI_NAME_MAX_LENGTH || !IsValidAlphaNumHyphenUnderscore(name, false) || inSystemEmoji(name) {
|
if name == "" || len(name) > EMOJI_NAME_MAX_LENGTH || !IsValidAlphaNumHyphenUnderscorePlus(name) || inSystemEmoji(name) {
|
||||||
return NewAppError("Emoji.IsValid", "model.emoji.name.app_error", nil, "", http.StatusBadRequest)
|
return NewAppError("Emoji.IsValid", "model.emoji.name.app_error", nil, "", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,9 @@ func TestEmojiIsValid(t *testing.T) {
|
|||||||
emoji.Name = "name-"
|
emoji.Name = "name-"
|
||||||
require.Nil(t, emoji.IsValid())
|
require.Nil(t, emoji.IsValid())
|
||||||
|
|
||||||
|
emoji.Name = "name+"
|
||||||
|
require.Nil(t, emoji.IsValid())
|
||||||
|
|
||||||
emoji.Name = "name_"
|
emoji.Name = "name_"
|
||||||
require.Nil(t, emoji.IsValid())
|
require.Nil(t, emoji.IsValid())
|
||||||
|
|
||||||
|
|||||||
@@ -438,6 +438,12 @@ func IsValidAlphaNumHyphenUnderscore(s string, withFormat bool) bool {
|
|||||||
return validSimpleAlphaNumHyphenUnderscore.MatchString(s)
|
return validSimpleAlphaNumHyphenUnderscore.MatchString(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsValidAlphaNumHyphenUnderscorePlus(s string) bool {
|
||||||
|
|
||||||
|
validSimpleAlphaNumHyphenUnderscorePlus := regexp.MustCompile(`^[a-zA-Z0-9+_-]+$`)
|
||||||
|
return validSimpleAlphaNumHyphenUnderscorePlus.MatchString(s)
|
||||||
|
}
|
||||||
|
|
||||||
func Etag(parts ...interface{}) string {
|
func Etag(parts ...interface{}) string {
|
||||||
|
|
||||||
etag := CurrentVersion
|
etag := CurrentVersion
|
||||||
|
|||||||
@@ -476,6 +476,84 @@ func TestIsValidAlphaNumHyphenUnderscore(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIsValidAlphaNumHyphenUnderscorePlus(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
Input string
|
||||||
|
Result bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
Input: "test",
|
||||||
|
Result: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: "test+name",
|
||||||
|
Result: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: "test+-name",
|
||||||
|
Result: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: "test_+name",
|
||||||
|
Result: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: "test++name",
|
||||||
|
Result: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: "test_-name",
|
||||||
|
Result: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: "-",
|
||||||
|
Result: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: "_",
|
||||||
|
Result: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: "+",
|
||||||
|
Result: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: "test+",
|
||||||
|
Result: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: "test++",
|
||||||
|
Result: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: "test--",
|
||||||
|
Result: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: "test__",
|
||||||
|
Result: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: ".",
|
||||||
|
Result: false,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
Input: "test,",
|
||||||
|
Result: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: "test:name",
|
||||||
|
Result: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range cases {
|
||||||
|
actual := IsValidAlphaNumHyphenUnderscorePlus(tc.Input)
|
||||||
|
require.Equalf(t, actual, tc.Result, "case: '%v'\tshould returned: %#v", tc.Input, tc.Result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestIsValidId(t *testing.T) {
|
func TestIsValidId(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
Input string
|
Input string
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user