]> source.dussan.org Git - redmine.git/commitdiff
Fix mentions of users with "@" in their username not working (#37138).
authorMarius Balteanu <marius.balteanu@zitec.com>
Mon, 20 Jun 2022 05:50:29 +0000 (05:50 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Mon, 20 Jun 2022 05:50:29 +0000 (05:50 +0000)
git-svn-id: https://svn.redmine.org/redmine/trunk@21660 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/acts/mentionable.rb
test/unit/lib/redmine/acts/mentionable_test.rb

index 264d1f50bfdc4c42d1d3646266ff627d50bf79f3..1629bbe410735efe1eac30dd6af2f64a0f42906a 100644 (file)
@@ -90,19 +90,20 @@ module Redmine
             content = content.gsub(%r{(~~~|```)(.*?)(~~~|```)}m, '')
           end
 
-          users = content.scan(MENTION_PATTERN).flatten
+          content.scan(MENTION_PATTERN).flatten
         end
 
         MENTION_PATTERN = /
-          (?:^|\W)                    # beginning of string or non-word char
-          @((?>[a-z0-9][a-z0-9-]*))   # @username
-          (?!\/)                      # without a trailing slash
+          (?:^|\W)
+          @([A-Za-z0-9_\-@\.]*?)
           (?=
-            \.+[ \t\W]|               # dots followed by space or non-word character
-            \.+$|                     # dots at end of line
-            [^0-9a-zA-Z_.]|           # non-word character except dot
-            $                         # end of line
-          )
+            (?=[[:punct:]][^A-Za-z0-9_\/])|
+            ,|
+            \.+$|
+            \s|
+            \]|
+            <|
+            $)
         /ix
       end
     end
index 9badcd6d2130917a4015fc7e6dfe9df4c7372bcb..cf01c328981d022645c2710bde3e7256731aba88 100644 (file)
@@ -34,6 +34,15 @@ class Redmine::Acts::MentionableTest < ActiveSupport::TestCase
     assert_equal [User.find(3)], issue.mentioned_users
   end
 
+  def test_mentioned_users_with_user_mention_having_mail_as_login
+    user = User.generate!(login: "foo@example.net")
+    User.add_to_project(user, Project.find(1), Role.find(1))
+
+    issue = Issue.generate!(project_id: 1, description: '@dlopper and @foo@example.net')
+
+    assert_equal [User.find(3), user], issue.mentioned_users
+  end
+
   def test_mentioned_users_with_multiple_mentions
     issue = Issue.generate!(project_id: 1, description: 'Hello @dlopper, @jsmith.')