diff --git a/lib/auto_link_scrubber.rb b/lib/auto_link_scrubber.rb index f6f6145eb..5ac9f2f3d 100644 --- a/lib/auto_link_scrubber.rb +++ b/lib/auto_link_scrubber.rb @@ -46,7 +46,7 @@ class AutoLinkScrubber < Loofah::Scrubber links.each do |link| nodes << doc.create_text_node(text[pos...link[:start]]) if link[:start] > pos - nodes << doc.create_element("a", link[:text], href: link[:href], rel: "noreferrer") + nodes << doc.create_element("a", link[:text], href: link[:href], rel: "noopener noreferrer") pos = link[:start] + link[:length] end nodes << doc.create_text_node(text[pos..]) if pos < text.length diff --git a/test/helpers/html_helper_test.rb b/test/helpers/html_helper_test.rb index b8c313e60..249a7f518 100644 --- a/test/helpers/html_helper_test.rb +++ b/test/helpers/html_helper_test.rb @@ -3,60 +3,60 @@ require "test_helper" class HtmlHelperTest < ActionView::TestCase test "convert URLs into anchor tags" do assert_equal_html \ - %(
Check this: https://example.com
), + %(Check this: https://example.com
), format_html("Check this: https://example.com
") assert_equal_html \ - %(Check this: https://example.com/
), + %(Check this: https://example.com/
), format_html("Check this: https://example.com/
") end test "don't include punctuation in URL autolinking" do assert_equal_html \ - %(Check this: https://example.com/!
), + %(Check this: https://example.com/!
), format_html("Check this: https://example.com/!
") assert_equal_html \ - %(Check this: https://example.com/.
), + %(Check this: https://example.com/.
), format_html("Check this: https://example.com/.
") assert_equal_html \ - %(Check this: https://example.com/?
), + %(Check this: https://example.com/?
), format_html("Check this: https://example.com/?
") assert_equal_html \ - %(Check this: https://example.com/,
), + %(Check this: https://example.com/,
), format_html("Check this: https://example.com/,
") assert_equal_html \ - %(Check this: https://example.com/:
), + %(Check this: https://example.com/:
), format_html("Check this: https://example.com/:
") assert_equal_html \ - %(Check this: https://example.com/;
), + %(Check this: https://example.com/;
), format_html("Check this: https://example.com/;
") assert_equal_html \ - %(Check this: https://example.com/"
), + %(Check this: https://example.com/"
), format_html("Check this: https://example.com/\"
") assert_equal_html \ - %(Check this: https://example.com/'
), + %(Check this: https://example.com/'
), format_html("Check this: https://example.com/'
") # trailing entities that decode to punctuation # use assert_equal and not assert_equal_html to make sure we're getting entities correct assert_equal \ - %(Check this: https://example.com/<
), + %(Check this: https://example.com/<
), format_html("Check this: https://example.com/<
") assert_equal \ - %(Check this: https://example.com/>
), + %(Check this: https://example.com/>
), format_html("Check this: https://example.com/>
") assert_equal \ - %(Check this: https://example.com/"
), + %(Check this: https://example.com/"
), format_html("Check this: https://example.com/"
") # multiple punctuation characters including entities assert_equal_html \ - %(Check this: https://example.com/!?;
), + %(Check this: https://example.com/!?;
), format_html("Check this: https://example.com/!?;
") assert_equal_html \ - %(<img src="https://example.com/">), + %(<img src="https://example.com/">), format_html(%(<img src="https://example.com/">)) assert_equal_html \ - %(<img src="https://example.com/"!>), + %(<img src="https://example.com/"!>), format_html(%(<img src="https://example.com/"!>)) end @@ -72,11 +72,11 @@ class HtmlHelperTest < ActionView::TestCase test "handle URLs with query parameters" do # use assert_equal and not assert_equal_html to make sure we're getting entities correct assert_equal \ - %(Check this: https://example.com/a?b=c&d=e
), + %(Check this: https://example.com/a?b=c&d=e
), format_html("Check this: https://example.com/a?b=c&d=e
") assert_equal \ - %(Check this: https://example.com/a?b=c&d=e
), + %(Check this: https://example.com/a?b=c&d=e
), format_html("Check this: https://example.com/a?b=c&d=e
") end @@ -88,7 +88,7 @@ class HtmlHelperTest < ActionView::TestCase test "convert email addresses into mailto links" do assert_equal_html \ - %(Contact us at support@example.com
), + %(Contact us at support@example.com
), format_html("Contact us at support@example.com
") end