-
Notifications
You must be signed in to change notification settings - Fork 0
feat: auto rel=noopener on target=_blank links (configurable) #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,7 @@ class Base | |
| abstract! | ||
|
|
||
| IGNORED_ON_PASSTHROUGH = T.let( | ||
| %w[class id href size large no-expander small target up size-sm size-lg style].freeze, | ||
| %w[class id href size large no-expander small target rel up size-sm size-lg style].freeze, | ||
| T::Array[String] | ||
| ) | ||
|
|
||
|
|
@@ -103,8 +103,20 @@ def combine_attributes(node, extra_classes = nil) | |
| end | ||
|
|
||
| sig { params(node: Nokogiri::XML::Node).returns(String) } | ||
| def target_attribute(node) | ||
| node.attributes['target'] ? %( target="#{escape_attr(node.attributes['target'])}") : '' | ||
| def link_attributes(node) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
README.md:285-287 documents Useful? React with 👍 / 👎. |
||
| target = node.attributes['target']&.value | ||
| rel = resolve_rel(node, target) | ||
| [ | ||
| target ? %( target="#{escape_attr(target)}") : '', | ||
| rel ? %( rel="#{escape_attr(rel)}") : '' | ||
| ].join | ||
| end | ||
|
|
||
| sig { params(node: Nokogiri::XML::Node, target: T.nilable(String)).returns(T.nilable(String)) } | ||
| def resolve_rel(node, target) | ||
| rel = node.attributes['rel']&.value | ||
| rel = nil if rel&.strip&.empty? | ||
| rel || (ActiveMail.configuration.blank_link_rel if target == '_blank') | ||
| end | ||
|
|
||
| # Outlook-safe nested-table structure kept in one place for <button> and <cta>. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,5 +2,5 @@ | |
| # frozen_string_literal: true | ||
|
|
||
| module ActiveMail | ||
| VERSION = '1.1.1' | ||
| VERSION = '1.2.0' | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For custom components that use the documented
pass_through_attributeshelper to build their own anchors, e.g. emitting<a #{pass_through_attributes(node)}>, a source attribute likerel="nofollow"is now stripped globally and that custom component never gets the built-inlink_attributespath that re-emits it. This silently drops author-supplied link semantics/security outside the three built-in link components; keeprelout of the generic passthrough ignore list or make the extra filtering local to the built-in anchor emitters.Useful? React with 👍 / 👎.