emoji: Disallow `.` in custom emoji names.

Until now, custom emojis with "periods" in their name were allowed, even though
they don't really fit the pattern of how we name them, and in fact the Markdown
processor would not render such custom emoji. Fix this by just disallowing the
character.

Also update the error strings accordingly.

Note that this does not include a migration to eliminate any existing custom emoji with this 
character in their name.

Fixes #24066.
This commit is contained in:
Lalit 2023-02-01 06:58:33 +05:30 committed by GitHub
parent 875ad8ed5b
commit 4ab824dc4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View File

@ -111,13 +111,13 @@ def check_remove_custom_emoji(user_profile: UserProfile, emoji_name: str) -> Non
def check_valid_emoji_name(emoji_name: str) -> None:
if emoji_name:
if re.match(r"^[0-9a-z.\-_]+(?<![.\-_])$", emoji_name):
if re.match(r"^[0-9a-z\-_]+(?<![\-_])$", emoji_name):
return
if re.match(r"^[0-9a-z.\-_]+$", emoji_name):
raise JsonableError(_("Emoji names must end with either a letter or number."))
if re.match(r"^[0-9a-z\-_]+$", emoji_name):
raise JsonableError(_("Emoji names must end with either a letter or digit."))
raise JsonableError(
_(
"Emoji names must contain only numbers, lowercase English letters, spaces, dashes, underscores, and periods.",
"Emoji names must contain only lowercase English letters, digits, spaces, dashes, and underscores.",
)
)
raise JsonableError(_("Emoji name is missing"))

View File

@ -120,7 +120,7 @@ class RealmEmojiTest(ZulipTestCase):
result = self.client_post("/json/realm/emoji/my_em*oji", info=emoji_data)
self.assert_json_error(
result,
"Emoji names must contain only numbers, lowercase English letters, spaces, dashes, underscores, and periods.",
"Emoji names must contain only lowercase English letters, digits, spaces, dashes, and underscores.",
)
def test_forward_slash_exception(self) -> None:
@ -132,7 +132,7 @@ class RealmEmojiTest(ZulipTestCase):
)
self.assert_json_error(
result,
"Emoji names must contain only numbers, lowercase English letters, spaces, dashes, underscores, and periods.",
"Emoji names must contain only lowercase English letters, digits, spaces, dashes, and underscores.",
)
def test_upload_uppercase_exception(self) -> None:
@ -142,7 +142,7 @@ class RealmEmojiTest(ZulipTestCase):
result = self.client_post("/json/realm/emoji/my_EMoji", info=emoji_data)
self.assert_json_error(
result,
"Emoji names must contain only numbers, lowercase English letters, spaces, dashes, underscores, and periods.",
"Emoji names must contain only lowercase English letters, digits, spaces, dashes, and underscores.",
)
def test_upload_end_character_exception(self) -> None:
@ -150,7 +150,7 @@ class RealmEmojiTest(ZulipTestCase):
with get_test_image_file("img.png") as fp1:
emoji_data = {"f1": fp1}
result = self.client_post("/json/realm/emoji/my_emoji_", info=emoji_data)
self.assert_json_error(result, "Emoji names must end with either a letter or number.")
self.assert_json_error(result, "Emoji names must end with either a letter or digit.")
def test_missing_name_exception(self) -> None:
self.login("iago")