From 0783bf43aa54978faaff5128f3b1d0307a3ee8eb Mon Sep 17 00:00:00 2001 From: Alain St-Denis Date: Sat, 15 Jul 2023 09:54:41 -0400 Subject: [PATCH] Remove unreachable code. Improve (I hope) the mention regex for raw text. --- federation/entities/activitypub/models.py | 10 +--------- federation/utils/text.py | 4 ++-- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/federation/entities/activitypub/models.py b/federation/entities/activitypub/models.py index f9df860..e7afbbe 100644 --- a/federation/entities/activitypub/models.py +++ b/federation/entities/activitypub/models.py @@ -874,21 +874,13 @@ class Note(Object, RawContentMixin): def extract_mentions(self): """ - Extract mentions from the inbound Mention objects. - - Also attempt to extract from raw_content if available + Attempt to extract mentions from raw_content if available """ if self.raw_content: super().extract_mentions() return - for mention in self.tag_objects: - if isinstance(mention, Mention): - profile = get_profile_or_entity(fid=mention.href) - handle = getattr(profile, 'finger', None) - if handle: self._mentions.add(handle) - @property def rendered_content(self): if self._soup: return str(self._soup) diff --git a/federation/utils/text.py b/federation/utils/text.py index e2cd78c..cbe6086 100644 --- a/federation/utils/text.py +++ b/federation/utils/text.py @@ -10,8 +10,8 @@ from commonmark import commonmark ILLEGAL_TAG_CHARS = "!#$%^&*+.,@£/()=?`'\\{[]}~;:\"’”—\xa0" TAG_PATTERN = re.compile(r'(#[\w]+)', re.UNICODE) -MENTION_PATTERN = re.compile(r'(@{?[\S ]?[^{}@]+[@;]?\s*[\w\-./@]+[\w/]+}?)', re.UNICODE) - +# This will match non matching braces. I don't think it's an issue. +MENTION_PATTERN = re.compile(r'(@\{?(?:[\w\-. \u263a-\U0001f645]*; *)?[\w]+@[\w\-.]+\.[\w]+}?)', re.UNICODE) def decode_if_bytes(text): try: