From 3ff58428b20a037480b4dc5fd605c92a1675f02b Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 29 2019 12:36:02 +0000 Subject: [PATCH 1/2] 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"(? Date: Jul 29 2019 12:48:08 +0000 Subject: [PATCH 2/2] Fix tests for new arrow version Signed-off-by: Pierre-Yves Chibon --- diff --git a/tests/test_pagure_admin.py b/tests/test_pagure_admin.py index ef9aef4..bbc8999 100644 --- a/tests/test_pagure_admin.py +++ b/tests/test_pagure_admin.py @@ -1633,7 +1633,7 @@ class PagureBlockUserTests(tests.Modeltests): pagure.cli.admin.do_block_user(args) output = output.getvalue() - self.assertEqual("No users are currently blocked\n", output) + self.assertIn("No users are currently blocked\n", output) @patch("pagure.cli.admin._ask_confirmation", MagicMock(return_value=True)) def test_list_blocked_user_with_date_and_data(self): @@ -1653,7 +1653,7 @@ class PagureBlockUserTests(tests.Modeltests): pagure.cli.admin.do_block_user(args) output = output.getvalue() - self.assertEqual( + self.assertIn( "Users blocked:\n" " pingou - 2050-12-31T00:00:00\n", output, @@ -1667,7 +1667,7 @@ class PagureBlockUserTests(tests.Modeltests): pagure.cli.admin.do_block_user(args) output = output.getvalue() - self.assertEqual("No users are currently blocked\n", output) + self.assertIn("No users are currently blocked\n", output) class PagureAdminDeleteProjectTests(tests.Modeltests):