diff --git a/naff/models/discord/emoji.py b/naff/models/discord/emoji.py index f74322abf..bc16bb130 100644 --- a/naff/models/discord/emoji.py +++ b/naff/models/discord/emoji.py @@ -1,5 +1,6 @@ import re import string +import unicodedata from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union import attrs @@ -22,7 +23,7 @@ __all__ = ("PartialEmoji", "CustomEmoji", "process_emoji_req_format", "process_emoji") emoji_regex = re.compile(r"?") -unicode_emoji_reg = re.compile(r"[^\w\s,]") +unicode_emoji_reg = re.compile(r"[^\w\s,’‘“”…–—•◦‣⁃⁎⁏⁒⁓⁺⁻⁼⁽⁾ⁿ₊₋₌₍₎]") @attrs.define(eq=False, order=False, hash=False, kw_only=False) @@ -87,7 +88,8 @@ def from_str(cls, emoji_str: str, *, language: str = "alias") -> Optional["Parti # the regex will match certain special characters, so this acts as a final failsafe if match not in string.printable: - return cls(name=match) + if unicodedata.category(match) == "So": + return cls(name=match) return None def __str__(self) -> str: diff --git a/tests/test_emoji.py b/tests/test_emoji.py index 927e18c68..b5dad4c95 100644 --- a/tests/test_emoji.py +++ b/tests/test_emoji.py @@ -107,3 +107,34 @@ def test_numerical_emoji() -> None: def test_false_positives() -> None: for _e in string.printable: assert PartialEmoji.from_str(_e) is None + + unicode_general_punctuation = [ + "’", + "‘", + "“", + "”", + "…", + "–", + "—", + "•", + "◦", + "‣", + "⁃", + "⁎", + "⁏", + "⁒", + "⁓", + "⁺", + "⁻", + "⁼", + "⁽", + "⁾", + "ⁿ", + "₊", + "₋", + "₌", + "₍", + "₎", + ] + for _e in unicode_general_punctuation: + assert PartialEmoji.from_str(_e) is None