Fix mention linkifying emails

This commit is contained in:
rubenwardy 2022-01-17 18:15:23 +00:00
parent a09f11d110
commit 9cc79d9fa5

@ -98,6 +98,8 @@ class MentionPattern(Pattern):
self.config = config self.config = config
def handleMatch(self, m): def handleMatch(self, m):
from app.models import User
label = m.group(2) label = m.group(2)
user = m.group(3) user = m.group(3)
package_name = m.group(4) package_name = m.group(4)
@ -107,6 +109,9 @@ class MentionPattern(Pattern):
el.set("href", url_for("packages.view", author=user, name=package_name)) el.set("href", url_for("packages.view", author=user, name=package_name))
return el return el
else: else:
if User.query.filter_by(username=user).count() == 0:
return None
el = ElementTree.Element("a") el = ElementTree.Element("a")
el.text = label el.text = label
el.set("href", url_for("users.profile", username=user)) el.set("href", url_for("users.profile", username=user))