lib/ahoy_email/processor.rb in ahoy_email-2.3.1 vs lib/ahoy_email/processor.rb in ahoy_email-2.4.0
- old
+ new
@@ -51,11 +51,11 @@
def track_links
if html_part?
part = message.html_part || message
- doc = Nokogiri::HTML::Document.parse(part.body.raw_source)
+ doc = parser_class.parse(part.body.raw_source)
doc.css("a[href]").each do |link|
uri = parse_uri(link["href"])
next unless trackable?(uri)
# utm params first
if options[:utm_params] && !skip_attribute?(link, "utm-params")
@@ -87,9 +87,22 @@
# not ideal, but should be equivalent in html5
# https://stackoverflow.com/questions/15776556/whats-the-difference-between-and-amp-in-html5
# escaping technically required before html5
# https://stackoverflow.com/questions/3705591/do-i-encode-ampersands-in-a-href
part.body = doc.to_s
+ end
+ end
+
+ # use document instead of fragment
+ # https://github.com/ankane/ahoy_email/pull/150
+ def parser_class
+ case options[:html5]
+ when true
+ Nokogiri::HTML5::Document
+ when false
+ Nokogiri::HTML4::Document
+ else
+ Nokogiri::HTML::Document
end
end
def html_part?
(message.html_part || message).content_type =~ /html/