]> source.dussan.org Git - redmine.git/commitdiff
Merge r21986 from trunk to 5.0-stable (#37755).
authorMarius Balteanu <marius.balteanu@zitec.com>
Sun, 4 Dec 2022 08:14:51 +0000 (08:14 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Sun, 4 Dec 2022 08:14:51 +0000 (08:14 +0000)
git-svn-id: https://svn.redmine.org/redmine/branches/5.0-stable@21988 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/application_helper.rb
test/helpers/application_helper_test.rb

index 3bb8a602dfb1b5dc9012e6dbcfd1f3c30e6e7f5b..5c5cf39a550a07e2c844f136f2a1f103f52e8fc4 100644 (file)
@@ -60,7 +60,7 @@ module ApplicationHelper
     case principal
     when User
       name = h(principal.name(options[:format]))
-      name = "@" + name if options[:mention]
+      name = "@".html_safe + name if options[:mention]
       css_classes = ''
       if principal.active? || (User.current.admin? && principal.logged?)
         url = user_url(principal, :only_path => only_path)
index 452892e8b05b82da7cf322f5a09f6018bead4803..c68f7495c2f6700c2258036e5e65d1da990ff43b 100644 (file)
@@ -1841,6 +1841,16 @@ class ApplicationHelperTest < Redmine::HelperTest
     assert_equal result, link_to_principal(unknown_principal, :class => 'bar')
   end
 
+  def test_link_to_principal_should_escape_principal_name
+    user = User.generate!(firstname: "firstname<>'", lastname: 'lastname&"')
+    group = Group.generate!(lastname: "group<>'&")
+
+    assert_include "firstname&lt;&gt;&#39; lastname&amp;&quot;", link_to_principal(user)
+    assert_include "@firstname&lt;&gt;&#39; lastname&amp;&quot;", link_to_principal(user, { mention: true })
+    assert_include "group&lt;&gt;&#39;&amp;", link_to_principal(group)
+    assert_include "&lt;&gt;&#39;&amp;", link_to_principal("<>'&")
+  end
+
   def test_link_to_group_should_return_only_group_name_for_non_admin_users
     User.current = nil
     group = Group.find(10)