Files
zulip/zephyr/lib/mention.py
Kevin Mehall ce131a7d69 Make the @-mention regex not match in the middle of the word.
Fixes issues with e.g. foo@hamlet.com (where hamlet is a user)

The \b was ineffective because @ made it always on a word boundary.
Instead, use the negative lookbehind trick from the URL regex.

(imported from commit fdca9bd686e4f8747e67b412cba1fa7c5c9391aa)
2013-07-15 13:26:44 -04:00

26 lines
654 B
Python

import re
from django.db.models import F, Q
import zephyr.models
# Match multi-word string between @** ** or match any one-word
# sequences after @
find_mentions = r'(?<![^\s\'\"\(,:<])@(?:\*\*([^\*]+)\*\*|(\w+))'
find_mentions_re = re.compile(find_mentions)
wildcards = ['all', 'everyone']
def find_user_for_mention(mention, realm):
if mention in wildcards:
return (True, None)
try:
user = zephyr.models.UserProfile.objects.filter(
Q(full_name__iexact=mention) | Q(short_name__iexact=mention),
realm=realm
)[0]
except IndexError:
user = None
return (False, user)