From 4ab824dc4ce6e9894c0e46c1b32c950455b1202d Mon Sep 17 00:00:00 2001 From: Lalit Date: Wed, 1 Feb 2023 06:58:33 +0530 Subject: [PATCH] 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. --- zerver/lib/emoji.py | 8 ++++---- zerver/tests/test_realm_emoji.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/zerver/lib/emoji.py b/zerver/lib/emoji.py index 862abf48d4..c406250337 100644 --- a/zerver/lib/emoji.py +++ b/zerver/lib/emoji.py @@ -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.\-_]+(? 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")