From 3ff58428b20a037480b4dc5fd605c92a1675f02b Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 29 2019 12:36:02 +0000 Subject: Ensure @ doesn't over-reach when sending notifications If someone comments in a ticket or a PR with a text that contains an email address, for example: foo@bar.com and the domain corresponds to an existing username, we do not want to notify that user. (Imagine if an `gmail` user gets created! :D) Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/lib/notify.py b/pagure/lib/notify.py index 77f7c64..7670ad1 100644 --- a/pagure/lib/notify.py +++ b/pagure/lib/notify.py @@ -34,6 +34,7 @@ import flask import pagure.lib.query import pagure.lib.tasks_services from pagure.config import config as pagure_config +from pagure.pfmarkdown import MENTION_RE _log = logging.getLogger(__name__) @@ -233,8 +234,7 @@ def _add_mentioned_users(emails, comment): """ Check the comment to see if an user is mentioned in it and if so add this user to the list of people to notify. """ - mentio_re = r"@(\w+)" - for username in re.findall(mentio_re, comment): + for username in re.findall(MENTION_RE, comment): user = pagure.lib.query.search_user(flask.g.session, username=username) if user: emails.add(user.default_email) diff --git a/pagure/pfmarkdown.py b/pagure/pfmarkdown.py index b46f48f..47d49a5 100644 --- a/pagure/pfmarkdown.py +++ b/pagure/pfmarkdown.py @@ -52,7 +52,7 @@ except ImportError: # MENTION_RE regex). Note that it is a zero-length match - it does # not capture or consume any of the string - and it does not appear # as a group for the match object. -MENTION_RE = r"(?