mirror of
https://github.com/redmine/redmine.git
synced 2025-11-14 17:26:06 +01:00
Add rel="noopener" to all external links with a target attribute (#37713).
Patch by Jens Krämer. git-svn-id: https://svn.redmine.org/redmine/trunk@21849 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -43,6 +43,12 @@ module Redmine
|
|||||||
klass,
|
klass,
|
||||||
(scheme == "mailto" ? "email" : "external")
|
(scheme == "mailto" ? "email" : "external")
|
||||||
].compact.join " "
|
].compact.join " "
|
||||||
|
|
||||||
|
if node["target"].present? && scheme != "mailto"
|
||||||
|
rel = node["rel"]&.split || []
|
||||||
|
rel << "noopener"
|
||||||
|
node["rel"] = rel.join(" ")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
doc
|
doc
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -50,5 +50,10 @@ if Object.const_defined?(:CommonMarker)
|
|||||||
filter(%(<a href="http://example.com/foo#bar#">Malformed URI</a>))
|
filter(%(<a href="http://example.com/foo#bar#">Malformed URI</a>))
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user