Patch #37713 » 0001-add-rel-noopener-to-all-external-links-with-a-target.patch
lib/redmine/wiki_formatting/common_mark/external_links_filter.rb | ||
---|---|---|
43 | 43 |
klass, |
44 | 44 |
(scheme == "mailto" ? "email" : "external") |
45 | 45 |
].compact.join " " |
46 | ||
47 |
if node["target"].present? && scheme != "mailto" |
|
48 |
rel = node["rel"]&.split || [] |
|
49 |
rel << "noopener" |
|
50 |
node["rel"] = rel.join(" ") |
|
51 |
end |
|
46 | 52 |
end |
47 | 53 |
doc |
48 | 54 |
end |
test/unit/lib/redmine/wiki_formatting/common_mark/external_links_filter_test.rb | ||
---|---|---|
50 | 50 |
filter(%(<a href="http://example.com/foo#bar#">Malformed URI</a>)) |
51 | 51 |
end |
52 | 52 |
end |
53 | ||
54 |
def test_external_links_with_target_get_rel_noopener |
|
55 |
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>)) |
|
56 |
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>)) |
|
57 |
end |
|
53 | 58 |
end |
54 | 59 |
end |