Skip to content

Commit fe109c9

Browse files
committed
test: ensure we pass with libxml 2.9.14
see release notes for Nokogiri v1.13.5
1 parent 9778c47 commit fe109c9

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

test/sanitizer_test.rb

+23-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
require "rails-html-sanitizer"
33
require "rails/dom/testing/assertions/dom_assertions"
44

5+
puts Nokogiri::VERSION_INFO
6+
57
class SanitizersTest < Minitest::Test
68
include Rails::Dom::Testing::Assertions::DomAssertions
79

@@ -54,7 +56,8 @@ def test_remove_xpaths_called_with_enumerable_xpaths
5456

5557
def test_strip_tags_with_quote
5658
input = '<" <img src="trollface.gif" onload="alert(1)"> hi'
57-
assert_equal ' hi', full_sanitize(input)
59+
expected = libxml_2_9_14_recovery? ? %{&lt;" hi} : %{ hi}
60+
assert_equal(expected, full_sanitize(input))
5861
end
5962

6063
def test_strip_invalid_html
@@ -75,15 +78,21 @@ def test_strip_tags_multiline
7578
end
7679

7780
def test_remove_unclosed_tags
78-
assert_equal "This is ", full_sanitize("This is <-- not\n a comment here.")
81+
input = "This is <-- not\n a comment here."
82+
expected = libxml_2_9_14_recovery? ? %{This is &lt;-- not\n a comment here.} : %{This is }
83+
assert_equal(expected, full_sanitize(input))
7984
end
8085

8186
def test_strip_cdata
82-
assert_equal "This has a ]]&gt; here.", full_sanitize("This has a <![CDATA[<section>]]> here.")
87+
input = "This has a <![CDATA[<section>]]> here."
88+
expected = libxml_2_9_14_recovery? ? %{This has a &lt;![CDATA[]]&gt; here.} : %{This has a ]]&gt; here.}
89+
assert_equal(expected, full_sanitize(input))
8390
end
8491

8592
def test_strip_unclosed_cdata
86-
assert_equal "This has an unclosed ]] here...", full_sanitize("This has an unclosed <![CDATA[<section>]] here...")
93+
input = "This has an unclosed <![CDATA[<section>]] here..."
94+
expected = libxml_2_9_14_recovery? ? %{This has an unclosed &lt;![CDATA[]] here...} : %{This has an unclosed ]] here...}
95+
assert_equal(expected, full_sanitize(input))
8796
end
8897

8998
def test_strip_blank_string
@@ -450,11 +459,15 @@ def test_should_sanitize_img_vbscript
450459
end
451460

452461
def test_should_sanitize_cdata_section
453-
assert_sanitized "<![CDATA[<span>section</span>]]>", "section]]&gt;"
462+
input = "<![CDATA[<span>section</span>]]>"
463+
expected = libxml_2_9_14_recovery? ? %{&lt;![CDATA[<span>section</span>]]&gt;} : %{section]]&gt;}
464+
assert_sanitized(input, expected)
454465
end
455466

456467
def test_should_sanitize_unterminated_cdata_section
457-
assert_sanitized "<![CDATA[<span>neverending...", "neverending..."
468+
input = "<![CDATA[<span>neverending..."
469+
expected = libxml_2_9_14_recovery? ? %{&lt;![CDATA[<span>neverending...</span>} : %{neverending...}
470+
assert_sanitized(input, expected)
458471
end
459472

460473
def test_should_not_mangle_urls_with_ampersand
@@ -626,4 +639,8 @@ def convert_to_css_hex(string, escape_parens=false)
626639
end
627640
end.join
628641
end
642+
643+
def libxml_2_9_14_recovery?
644+
Nokogiri.method(:uses_libxml?).arity == -1 && Nokogiri.uses_libxml?(">= 2.9.14")
645+
end
629646
end

0 commit comments

Comments
 (0)