diff --git a/tildes/tests/test_comment_user_mentions.py b/tildes/tests/test_comment_user_mentions.py index eacbc52..ac2ef72 100644 --- a/tildes/tests/test_comment_user_mentions.py +++ b/tildes/tests/test_comment_user_mentions.py @@ -36,6 +36,14 @@ def test_get_mentions_for_comment(db, user_list, comment): assert mentions[index].user == user +def test_get_mentions_for_comment_escapes_with_backslash(db, user_list, comment): + """Test that backslash escaped mentions are ignored.""" + comment.markdown = "@foo @bar. \@baz!" + mentions = CommentNotification.get_mentions_for_comment(db, comment) + assert len(mentions) == 2 + assert "baz" not in [mention.user for mention in mentions] + + def test_mention_filtering_parent_comment(db, topic, user_list): """Test notification filtering for parent comments.""" parent_comment = Comment(topic, user_list[0], "Comment content.") diff --git a/tildes/tildes/lib/markdown.py b/tildes/tildes/lib/markdown.py index e1dcda4..9bde3b3 100644 --- a/tildes/tildes/lib/markdown.py +++ b/tildes/tildes/lib/markdown.py @@ -293,7 +293,7 @@ class LinkifyFilter(Filter): # Regex that finds probable references to users. As above, this isn't "perfect" # either but works as an initial pass with the validity of the username checked more # carefully later. - USERNAME_REFERENCE_REGEX = re.compile(r"(?