View Issue Details

IDProjectCategoryView StatusLast Update
0025698mantisbtmentionspublic2022-02-13 22:39
ReporterMaurycy Assigned To 
PrioritynormalSeverityminorReproducibilityhave not tried
Status confirmedResolutionopen 
Product Version2.19.0 
Summary0025698: Mentions does not work when user login is an email
Description

In our organization all logins are oganizational email accounts. Also in Mantis we use emails as logins (usernames). Unfortunately that causes that mentioning does not work, because it does not include char @ as possible element of user name.

Additional Information

Currently the pattern matching for mentions looks like that:

        $s_pattern = '/(?:'
            # Negative lookbehind to ensure we have whitespace or start of
            # string before the tag - ensures we don't match a tag in the
            # middle of a word (e.g. e-mail address)
            . '(?<=^|[^\w])'
            # Negative lookbehind  to ensure we don't match multiple tags
            . '(?<!' . $t_quoted_tag . ')' . $t_quoted_tag
            . ')'
            # any word char, dash or period, must end with word char
            . '([\w\-.]*[\w])'
            # Lookforward to ensure next char is not a valid mention char or
            # the end of the string, or the mention tag
            . '(?=[^\w@]|$)'
            . '(?!$t_quoted_tag)'
            . '/';

My proposition is to extend it like this:

        $s_pattern = '/(?:'
            # Negative lookbehind to ensure we have whitespace or start of
            # string before the tag - ensures we don't match a tag in the
            # middle of a word (e.g. e-mail address)
            . '(?<=^|[^\w])'
            # Negative lookbehind  to ensure we don't match multiple tags
            . '(?<!' . $t_quoted_tag . ')' . $t_quoted_tag
            . ')'
            # any word char, dash, period or at sign, must end with word char
            . '([\w\-.@]*[\w])'
            # Lookforward to ensure next char is not a valid mention char or
            # the end of the string, or the mention tag
            . '(?=[^\w@]|$)'
            . '(?!$t_quoted_tag)'
            . '/';

I've tested this pattern and it seems to work, see: https://regex101.com/r/gkitVn/1

TagsNo tags attached.
Attached Files

Relationships

related to 0024883 new Mentioning user name with space does not work 
has duplicate 0022484 closedatrol Mentions functionality fails if user name format is like email address 

Activities

dregad

dregad

2019-04-18 03:45

developer   ~0061962

The updated regex allows any number of @ signs in the string, which would not be a valid username identifier, but considering that we only create the link if the pattern match corresponds to an existing user, it probably would not be a problem.

Maurycy

Maurycy

2019-04-18 03:53

reporter   ~0061963

True... we could change it from ([\w\-.@]*[\w]) to ([\w\-.]*@?[\w\-.]*[\w])

Maurycy

Maurycy

2019-04-19 06:21

reporter   ~0061982

Attached patch file that allows for single @ sign inside user name.

mention_api.php.patch (771 bytes)   
Index: core/mention_api.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/mention_api.php	(date 1555667913000)
+++ core/mention_api.php	(date 1555668521000)
@@ -73,8 +73,8 @@
 			# Negative lookbehind  to ensure we don't match multiple tags
 			. '(?<!' . $t_quoted_tag . ')' . $t_quoted_tag
 			. ')'
-			# any word char, dash or period, must end with word char
-			. '([\w\-.]*[\w])'
+			# any word char, dash, period or single @ char, must end with word char
+			. '([\w\-.]*@?[\w\-.]*[\w])'
 			# Lookforward to ensure next char is not a valid mention char or
 			# the end of the string, or the mention tag
 			. '(?=[^\w@]|$)'
mention_api.php.patch (771 bytes)