Skip to content

Commit fb152b1

Browse files
committed
test: libxml 2.9.11 handles namespaces in HTML docs differently
Update tests to pass with this version.
1 parent 3db4cc7 commit fb152b1

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

test/integration/test_ad_hoc.rb

+10-3
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,20 @@ def test_whitewash_on_fragment
7979

8080
def test_fragment_whitewash_on_microsofty_markup
8181
whitewashed = Loofah.fragment(MSWORD_HTML).scrub!(:whitewash)
82-
assert_equal "<p>Foo <b>BOLD</b></p>", whitewashed.to_s.strip
82+
if Nokogiri.uses_libxml?("<2.9.11")
83+
assert_equal "<p>Foo <b>BOLD</b></p>", whitewashed.to_s.strip
84+
else
85+
assert_equal "<p>Foo <b>BOLD<p></p></b></p>", whitewashed.to_s.strip
86+
end
8387
end
8488

8589
def test_document_whitewash_on_microsofty_markup
8690
whitewashed = Loofah.document(MSWORD_HTML).scrub!(:whitewash)
87-
assert_match %r(<p>Foo <b>BOLD</b></p>), whitewashed.to_s
88-
assert_equal "<p>Foo <b>BOLD</b></p>", whitewashed.xpath("/html/body/*").to_s
91+
if Nokogiri.uses_libxml?("<2.9.11")
92+
assert_equal "<p>Foo <b>BOLD</b></p>", whitewashed.xpath("/html/body/*").to_s
93+
else
94+
assert_equal "<p>Foo <b>BOLD<p></p></b></p>", whitewashed.xpath("/html/body/*").to_s
95+
end
8996
end
9097

9198
def test_return_empty_string_when_nothing_left

test/integration/test_scrubbers.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class IntegrationTestScrubbers < Loofah::TestCase
88

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

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

71-
assert_equal WHITEWASH_RESULT, doc.xpath("/html/body").inner_html
72+
ww_result = Nokogiri.uses_libxml?("<2.9.11") ? WHITEWASH_RESULT : WHITEWASH_RESULT_LIBXML2911
73+
assert_equal ww_result, doc.xpath("/html/body").inner_html
7274
assert_equal doc, result
7375
end
7476
end
@@ -246,7 +248,8 @@ class IntegrationTestScrubbers < Loofah::TestCase
246248
doc = Loofah::HTML::DocumentFragment.parse "<div>#{WHITEWASH_FRAGMENT}</div>"
247249
result = doc.scrub! :whitewash
248250

249-
assert_equal WHITEWASH_RESULT, doc.xpath("./div").inner_html
251+
ww_result = Nokogiri.uses_libxml?("<2.9.11") ? WHITEWASH_RESULT : WHITEWASH_RESULT_LIBXML2911
252+
assert_equal ww_result, doc.xpath("./div").inner_html
250253
assert_equal doc, result
251254
end
252255
end

0 commit comments

Comments
 (0)