Skip to content

Commit 11752a6

Browse files
committed
tests: handle libxml 2.10.0 incorrectly-opened comment parsing
Related, see: - sparklemotion/nokogiri#2625 - https://gitlab.gnome.org/GNOME/libxml2/-/issues/380
1 parent f83f08c commit 11752a6

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

test/sanitizer_test.rb

+14-7
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def test_remove_xpaths_called_with_enumerable_xpaths
5454

5555
def test_strip_tags_with_quote
5656
input = '<" <img src="trollface.gif" onload="alert(1)"> hi'
57-
expected = libxml_2_9_14_recovery? ? %{&lt;" hi} : %{ hi}
57+
expected = libxml_2_9_14_recovery_lt? ? %{&lt;" hi} : %{ hi}
5858
assert_equal(expected, full_sanitize(input))
5959
end
6060

@@ -77,19 +77,19 @@ def test_strip_tags_multiline
7777

7878
def test_remove_unclosed_tags
7979
input = "This is <-- not\n a comment here."
80-
expected = libxml_2_9_14_recovery? ? %{This is &lt;-- not\n a comment here.} : %{This is }
80+
expected = libxml_2_9_14_recovery_lt? ? %{This is &lt;-- not\n a comment here.} : %{This is }
8181
assert_equal(expected, full_sanitize(input))
8282
end
8383

8484
def test_strip_cdata
8585
input = "This has a <![CDATA[<section>]]> here."
86-
expected = libxml_2_9_14_recovery? ? %{This has a &lt;![CDATA[]]&gt; here.} : %{This has a ]]&gt; here.}
86+
expected = libxml_2_9_14_recovery_lt_bang? ? %{This has a &lt;![CDATA[]]&gt; here.} : %{This has a ]]&gt; here.}
8787
assert_equal(expected, full_sanitize(input))
8888
end
8989

9090
def test_strip_unclosed_cdata
9191
input = "This has an unclosed <![CDATA[<section>]] here..."
92-
expected = libxml_2_9_14_recovery? ? %{This has an unclosed &lt;![CDATA[]] here...} : %{This has an unclosed ]] here...}
92+
expected = libxml_2_9_14_recovery_lt_bang? ? %{This has an unclosed &lt;![CDATA[]] here...} : %{This has an unclosed ]] here...}
9393
assert_equal(expected, full_sanitize(input))
9494
end
9595

@@ -458,13 +458,13 @@ def test_should_sanitize_img_vbscript
458458

459459
def test_should_sanitize_cdata_section
460460
input = "<![CDATA[<span>section</span>]]>"
461-
expected = libxml_2_9_14_recovery? ? %{&lt;![CDATA[<span>section</span>]]&gt;} : %{section]]&gt;}
461+
expected = libxml_2_9_14_recovery_lt_bang? ? %{&lt;![CDATA[<span>section</span>]]&gt;} : %{section]]&gt;}
462462
assert_sanitized(input, expected)
463463
end
464464

465465
def test_should_sanitize_unterminated_cdata_section
466466
input = "<![CDATA[<span>neverending..."
467-
expected = libxml_2_9_14_recovery? ? %{&lt;![CDATA[<span>neverending...</span>} : %{neverending...}
467+
expected = libxml_2_9_14_recovery_lt_bang? ? %{&lt;![CDATA[<span>neverending...</span>} : %{neverending...}
468468
assert_sanitized(input, expected)
469469
end
470470

@@ -657,10 +657,17 @@ def convert_to_css_hex(string, escape_parens=false)
657657
end.join
658658
end
659659

660-
def libxml_2_9_14_recovery?
660+
def libxml_2_9_14_recovery_lt?
661+
# changed in 2.9.14, see https://github.com/sparklemotion/nokogiri/releases/tag/v1.13.5
661662
Nokogiri.method(:uses_libxml?).arity == -1 && Nokogiri.uses_libxml?(">= 2.9.14")
662663
end
663664

665+
def libxml_2_9_14_recovery_lt_bang?
666+
# changed in 2.9.14, see https://github.com/sparklemotion/nokogiri/releases/tag/v1.13.5
667+
# then reverted in 2.10.0, see https://gitlab.gnome.org/GNOME/libxml2/-/issues/380
668+
Nokogiri.method(:uses_libxml?).arity == -1 && Nokogiri.uses_libxml?("= 2.9.14")
669+
end
670+
664671
def html5_mode?
665672
::Loofah.respond_to?(:html5_mode?) && ::Loofah.html5_mode?
666673
end

0 commit comments

Comments
 (0)