2
2
require "rails-html-sanitizer"
3
3
require "rails/dom/testing/assertions/dom_assertions"
4
4
5
+ puts Nokogiri ::VERSION_INFO
6
+
5
7
class SanitizersTest < Minitest ::Test
6
8
include Rails ::Dom ::Testing ::Assertions ::DomAssertions
7
9
@@ -54,7 +56,8 @@ def test_remove_xpaths_called_with_enumerable_xpaths
54
56
55
57
def test_strip_tags_with_quote
56
58
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 ) )
58
61
end
59
62
60
63
def test_strip_invalid_html
@@ -75,15 +78,21 @@ def test_strip_tags_multiline
75
78
end
76
79
77
80
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 ) )
79
84
end
80
85
81
86
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 ) )
83
90
end
84
91
85
92
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 ) )
87
96
end
88
97
89
98
def test_strip_blank_string
@@ -450,11 +459,15 @@ def test_should_sanitize_img_vbscript
450
459
end
451
460
452
461
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 )
454
465
end
455
466
456
467
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 )
458
471
end
459
472
460
473
def test_should_not_mangle_urls_with_ampersand
@@ -626,4 +639,8 @@ def convert_to_css_hex(string, escape_parens=false)
626
639
end
627
640
end . join
628
641
end
642
+
643
+ def libxml_2_9_14_recovery?
644
+ Nokogiri . method ( :uses_libxml? ) . arity == -1 && Nokogiri . uses_libxml? ( ">= 2.9.14" )
645
+ end
629
646
end
0 commit comments