diff --git a/lib/text_helpers/translation.rb b/lib/text_helpers/translation.rb
index bf80f06..6c9d314 100644
--- a/lib/text_helpers/translation.rb
+++ b/lib/text_helpers/translation.rb
@@ -12,7 +12,7 @@ def link(link, title, content)
attributes = [
("href=\"#{link}\"" if link),
("title=\"#{title}\"" if title),
- ("target=\"_blank\"" if link =~ PROTOCOL_MATCHER),
+ ("target=\"_blank\" rel=\"noopener\"" if link.match?(PROTOCOL_MATCHER)),
]
"#{content}"
@@ -44,7 +44,7 @@ def text(key, options = {})
interpolation_options = { cascade: true }.merge(options)
# Interpolate any keypaths (e.g., `!some.lookup.path/key!`) found in the text.
- while text =~ KEYPATH_MATCHER do
+ while text.match?(KEYPATH_MATCHER) do
text = text.gsub(KEYPATH_MATCHER) { |match| I18n.t($1, **interpolation_options) }
end
diff --git a/test/lib/text_helpers/translation_test.rb b/test/lib/text_helpers/translation_test.rb
index 31cce09..0a30650 100644
--- a/test/lib/text_helpers/translation_test.rb
+++ b/test/lib/text_helpers/translation_test.rb
@@ -119,12 +119,12 @@
assert_equal "#{@scoped_text}\n", @helper.html(:test_key, inline: true, orphans: true)
end
- it "renders internal links without a target" do
+ it "renders internal links without a target or rel" do
assert_equal "Internal link\n", @helper.html(:internal_link, inline: true)
end
- it "renders external links with target='_blank'" do
- assert_equal "External link\n", @helper.html(:external_link, inline: true)
+ it "renders external links with target='_blank' and rel='noopener'" do
+ assert_equal "External link\n", @helper.html(:external_link, inline: true)
end
it "interpolates values wrapped in !!" do