Skip to content
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

test: libxml 2.9.11 handles namespaces in HTML docs differently #207

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions test/integration/test_ad_hoc.rb
Expand Up @@ -79,13 +79,20 @@ def test_whitewash_on_fragment

def test_fragment_whitewash_on_microsofty_markup
whitewashed = Loofah.fragment(MSWORD_HTML).scrub!(:whitewash)
assert_equal "<p>Foo <b>BOLD</b></p>", whitewashed.to_s.strip
if Nokogiri.uses_libxml?("<2.9.11")
assert_equal "<p>Foo <b>BOLD</b></p>", whitewashed.to_s.strip
else
assert_equal "<p>Foo <b>BOLD<p></p></b></p>", whitewashed.to_s.strip
end
end

def test_document_whitewash_on_microsofty_markup
whitewashed = Loofah.document(MSWORD_HTML).scrub!(:whitewash)
assert_match %r(<p>Foo <b>BOLD</b></p>), whitewashed.to_s
assert_equal "<p>Foo <b>BOLD</b></p>", whitewashed.xpath("/html/body/*").to_s
if Nokogiri.uses_libxml?("<2.9.11")
assert_equal "<p>Foo <b>BOLD</b></p>", whitewashed.xpath("/html/body/*").to_s
else
assert_equal "<p>Foo <b>BOLD<p></p></b></p>", whitewashed.xpath("/html/body/*").to_s
end
end

def test_return_empty_string_when_nothing_left
Expand Down
7 changes: 5 additions & 2 deletions test/integration/test_scrubbers.rb
Expand Up @@ -8,6 +8,7 @@ class IntegrationTestScrubbers < Loofah::TestCase

WHITEWASH_FRAGMENT = "<o:div>no</o:div><div id='no'>foo</div><invalid>bar</invalid><!--[if gts mso9]><div>microsofty stuff</div><![endif]-->"
WHITEWASH_RESULT = "<div>foo</div>"
WHITEWASH_RESULT_LIBXML2911 = "<div>no</div>\n<div>foo</div>"

NOFOLLOW_FRAGMENT = '<a href="http://www.example.com/">Click here</a>'
NOFOLLOW_RESULT = '<a href="http://www.example.com/" rel="nofollow">Click here</a>'
Expand Down Expand Up @@ -68,7 +69,8 @@ class IntegrationTestScrubbers < Loofah::TestCase
doc = Loofah::HTML::Document.parse "<html><body>#{WHITEWASH_FRAGMENT}</body></html>"
result = doc.scrub! :whitewash

assert_equal WHITEWASH_RESULT, doc.xpath("/html/body").inner_html
ww_result = Nokogiri.uses_libxml?("<2.9.11") ? WHITEWASH_RESULT : WHITEWASH_RESULT_LIBXML2911
assert_equal ww_result, doc.xpath("/html/body").inner_html
assert_equal doc, result
end
end
Expand Down Expand Up @@ -246,7 +248,8 @@ class IntegrationTestScrubbers < Loofah::TestCase
doc = Loofah::HTML::DocumentFragment.parse "<div>#{WHITEWASH_FRAGMENT}</div>"
result = doc.scrub! :whitewash

assert_equal WHITEWASH_RESULT, doc.xpath("./div").inner_html
ww_result = Nokogiri.uses_libxml?("<2.9.11") ? WHITEWASH_RESULT : WHITEWASH_RESULT_LIBXML2911
assert_equal ww_result, doc.xpath("./div").inner_html
assert_equal doc, result
end
end
Expand Down