From 53d919f8c14c6a02becfe13c01ad2b4260efdb38 Mon Sep 17 00:00:00 2001
From: Adam Williamson
Date: Feb 22 2018 10:36:38 +0000
Subject: Don't treat @ in the middle of words as a mention
If there's a user called 'example', then *any* occurence of the
string `@example` followed by a non-word character is treated
as a mention. This is not how we handle this for anything else
(e.g. issue or PR links) and has some obvious weird effects...
like the string `someone@example.com` is treated as a mention
of the user @example. So, let's not do that any more (by using
the same negative lookbehind we use for other things).
Also, drop the leading space from the `text` definition used in
the pattern's `handleMatch()`. The regex doesn't capture any
character before the @ and has not done for a long time, if it
ever did, so this is just wrong. If you look at the raw page
source of any Pagure page with an @mention in it, you can see
that there's a bogus extra space before the @ due to this,
though it seems that browsers (at least Firefox) strip it when
rendering the HTML.
Also add an explanation of what these negative lookbehinds we
keep using are for, and how they work, since here above the
first regex is a logical place, and @pingou asked for one...
Signed-off-by: Adam Williamson
---
diff --git a/pagure/pfmarkdown.py b/pagure/pfmarkdown.py
index 9fe6ddf..3d342a5 100644
--- a/pagure/pfmarkdown.py
+++ b/pagure/pfmarkdown.py
@@ -31,9 +31,16 @@ import pagure.lib
from pagure.config import config as pagure_config
-MENTION_RE = r'@(\w+)'
+# the (?~~foo bar~~
',
# '~~foo bar~~ and ~~another ~~',
'foo bar and another
',
+ # 'lets mention @pingou',
+ 'lets mention @pingou
',
+ # '@pingou at start of line',
+ '@pingou at start of line
',
+ # 'but not someone@pingou.com',
+ 'but not someone@pingou.com
',
]
with self.app.application.app_context():