]> source.dussan.org Git - redmine.git/commitdiff
Merged r21849 from trunk to 5.0-stable (#37713).
authorMarius Balteanu <marius.balteanu@zitec.com>
Tue, 27 Sep 2022 17:10:14 +0000 (17:10 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Tue, 27 Sep 2022 17:10:14 +0000 (17:10 +0000)
git-svn-id: https://svn.redmine.org/redmine/branches/5.0-stable@21858 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/wiki_formatting/common_mark/external_links_filter.rb
test/unit/lib/redmine/wiki_formatting/common_mark/external_links_filter_test.rb

index 4c25a7b133981679fb096a4b58712dcbaaeb0ace..a62ac680fe463c68dee741b179c906d3b89c6601 100644 (file)
@@ -39,6 +39,12 @@ module Redmine
               klass,
               (scheme == "mailto" ? "email" : "external")
             ].compact.join " "
+
+            if node["target"].present? && scheme != "mailto"
+              rel = node["rel"]&.split || []
+              rel << "noopener"
+              node["rel"] = rel.join(" ")
+            end
           end
           doc
         end
index d4b76c401c6c28cdf648725cb787779fd8cab1ea..f46f69c2ed5e17562d1e48ce5c0be8a10cc2281c 100644 (file)
@@ -50,5 +50,10 @@ if Object.const_defined?(:CommonMarker)
         filter(%(<a href="http://example.com/foo#bar#">Malformed URI</a>))
       end
     end
+
+    def test_external_links_with_target_get_rel_noopener
+      assert_equal %(<a target="_blank" href="http://example.net/" class="external" rel="noopener">link</a>), filter(%(<a target="_blank" href="http://example.net/">link</a>))
+      assert_equal %(<a target="_blank" href="http://example.net/" rel="nofollow noopener" class="external">link</a>), filter(%(<a target="_blank" href="http://example.net/" rel="nofollow">link</a>))
+    end
   end
 end