22require "rails-html-sanitizer"
33require "rails/dom/testing/assertions/dom_assertions"
44
5+ puts Nokogiri ::VERSION_INFO
6+
57class 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? ? %{<" 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 <-- 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 ]]> 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 <![CDATA[]]> here.} : %{This has a ]]> 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 <![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]]>"
462+ input = "<![CDATA[<span>section</span>]]>"
463+ expected = libxml_2_9_14_recovery? ? %{<![CDATA[<span>section</span>]]>} : %{section]]>}
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? ? %{<![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
629646end
0 commit comments