diff --git a/lib/html_sanitizer.rb b/lib/html_sanitizer.rb index d8d127f0e..10db5316e 100644 --- a/lib/html_sanitizer.rb +++ b/lib/html_sanitizer.rb @@ -145,7 +145,10 @@ satinize html string based on whiltelist # check if href is different to text if external && node.name == 'a' && !url_same?(node['href'], node.text) - if node.children.empty? || node.children.first.class == Nokogiri::XML::Text + if node['href'].blank? + node.replace strict(node.children.to_s) + Loofah::Scrubber::STOP + elsif node.children.empty? || node.children.first.class == Nokogiri::XML::Text text = Nokogiri::XML::Text.new("#{node['href']} (", node.document) node.add_previous_sibling(text) node['href'] = cleanup_target(node.text) @@ -257,7 +260,10 @@ cleanup html string: # check if href is different to text if node.name == 'a' && !url_same?(node['href'], node.text) - if node.children.empty? || node.children.first.class == Nokogiri::XML::Text + if node['href'].blank? + node.replace cleanup_structure(node.children.to_s) + Loofah::Scrubber::STOP + elsif node.children.empty? || node.children.first.class == Nokogiri::XML::Text text = Nokogiri::XML::Text.new("#{node.text} (", node.document) node.add_previous_sibling(text) node.content = cleanup_target(node['href']) diff --git a/test/unit/aaa_string_test.rb b/test/unit/aaa_string_test.rb index d23f4d3b8..c303f5b65 100644 --- a/test/unit/aaa_string_test.rb +++ b/test/unit/aaa_string_test.rb @@ -620,6 +620,10 @@ Men-----------------------' result = "Damit Sie keinen Tag versäumen, empfehlen wir Ihnen den Link des Adventkalenders (http://newsletters.cylex.de/) in
Ihrer Lesezeichen-Symbolleiste zu ergänzen.
" assert_equal(result, html.html2html_strict) + html = 'Hello Mr Smith,' + result = 'Hello Mr Smith,' + assert_equal(result, html.html2html_strict) + html = "
abc

Von: Fritz Bauer [mailto:me@example.com]
Gesendet: Donnerstag, 3. Mai 2012 11:51
An: John Smith
Cc: Smith, John Marian; johnel.fratczak@example.com; ole.brei@example.com; Günther John | Example GmbH; bkopon@example.com; john.heisterhagen@team.example.com; sven.rocked@example.com; michael.house@example.com; tgutzeit@example.com
Betreff: Re: OTRS::XXX Erweiterung - Anhänge an CI's

" result = "
abc

Von: Fritz Bauer [mailto:me@example.com]
Gesendet: Donnerstag, 3. Mai 2012 11:51
An: John Smith
Cc: Smith, John Marian; johnel.fratczak@example.com; ole.brei@example.com; Günther John | Example GmbH; bkopon@example.com; john.heisterhagen@team.example.com; sven.rocked@example.com; michael.house@example.com; tgutzeit@example.com
Betreff: Re: OTRS::XXX Erweiterung - Anhänge an CI's

\n
"