diff --git a/test/sanitizer_test.rb b/test/sanitizer_test.rb
index 1de5a99..8b0b7ab 100644
--- a/test/sanitizer_test.rb
+++ b/test/sanitizer_test.rb
@@ -2,6 +2,8 @@
require "rails-html-sanitizer"
require "rails/dom/testing/assertions/dom_assertions"
+puts Nokogiri::VERSION_INFO
+
class SanitizersTest < Minitest::Test
include Rails::Dom::Testing::Assertions::DomAssertions
@@ -54,7 +56,8 @@ def test_remove_xpaths_called_with_enumerable_xpaths
def test_strip_tags_with_quote
input = '<" hi'
- assert_equal ' hi', full_sanitize(input)
+ expected = libxml_2_9_14_recovery? ? %{<" hi} : %{ hi}
+ assert_equal(expected, full_sanitize(input))
end
def test_strip_invalid_html
@@ -75,15 +78,21 @@ def test_strip_tags_multiline
end
def test_remove_unclosed_tags
- assert_equal "This is ", full_sanitize("This is <-- not\n a comment here.")
+ input = "This is <-- not\n a comment here."
+ expected = libxml_2_9_14_recovery? ? %{This is <-- not\n a comment here.} : %{This is }
+ assert_equal(expected, full_sanitize(input))
end
def test_strip_cdata
- assert_equal "This has a ]]> here.", full_sanitize("This has a ]]> here.")
+ input = "This has a ]]> here."
+ expected = libxml_2_9_14_recovery? ? %{This has a <![CDATA[]]> here.} : %{This has a ]]> here.}
+ assert_equal(expected, full_sanitize(input))
end
def test_strip_unclosed_cdata
- assert_equal "This has an unclosed ]] here...", full_sanitize("This has an unclosed ]] here...")
+ input = "This has an unclosed ]] here..."
+ expected = libxml_2_9_14_recovery? ? %{This has an unclosed <![CDATA[]] here...} : %{This has an unclosed ]] here...}
+ assert_equal(expected, full_sanitize(input))
end
def test_strip_blank_string
@@ -450,11 +459,15 @@ def test_should_sanitize_img_vbscript
end
def test_should_sanitize_cdata_section
- assert_sanitized "section]]>", "section]]>"
+ input = "section]]>"
+ expected = libxml_2_9_14_recovery? ? %{<![CDATA[section]]>} : %{section]]>}
+ assert_sanitized(input, expected)
end
def test_should_sanitize_unterminated_cdata_section
- assert_sanitized "neverending...", "neverending..."
+ input = "neverending..."
+ expected = libxml_2_9_14_recovery? ? %{<![CDATA[neverending...} : %{neverending...}
+ assert_sanitized(input, expected)
end
def test_should_not_mangle_urls_with_ampersand
@@ -626,4 +639,8 @@ def convert_to_css_hex(string, escape_parens=false)
end
end.join
end
+
+ def libxml_2_9_14_recovery?
+ Nokogiri.method(:uses_libxml?).arity == -1 && Nokogiri.uses_libxml?(">= 2.9.14")
+ end
end