Browse Source

Ignore user mentions if the @ is escaped

merge-requests/86/head
Timo 5 years ago
committed by Deimos
parent
commit
275276da00
  1. 8
      tildes/tests/test_comment_user_mentions.py
  2. 2
      tildes/tildes/lib/markdown.py

8
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.")

2
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"(?<!\w)(?:/?u/|@)([\w-]+)\b")
USERNAME_REFERENCE_REGEX = re.compile(r"(?<![\w\\])(?:/?u/|@)([\w-]+)\b")
def __init__(
self, source: NonRecursiveTreeWalker, skip_tags: Optional[List[str]] = None

Loading…
Cancel
Save