Class | SanitizeTest |
In: |
lib/feed_tools/vendor/html5/tests/test_sanitizer.rb
|
Parent: | Test::Unit::TestCase |
# File lib/feed_tools/vendor/html5/tests/test_sanitizer.rb, line 34 34: def check_sanitization(input, htmloutput, xhtmloutput, rexmloutput) 35: assert_equal htmloutput, sanitize_html(input) 36: assert_equal xhtmloutput, sanitize_xhtml(input) 37: assert_equal rexmloutput, sanitize_rexml(input) 38: end
# File lib/feed_tools/vendor/html5/tests/test_sanitizer.rb, line 18 18: def sanitize_html stream 19: HTMLParser.parse_fragment(stream, {:tokenizer => HTMLSanitizer, :encoding => 'utf-8', :lowercase_element_name => false, :lowercase_attr_name => false}).to_s 20: end
# File lib/feed_tools/vendor/html5/tests/test_sanitizer.rb, line 22 22: def sanitize_rexml stream 23: require 'rexml/document' 24: doc = REXML::Document.new("<div xmlns='http://www.w3.org/1999/xhtml'>#{stream}</div>") 25: tokens = TreeWalkers.get_tree_walker('rexml').new(doc) 26: XHTMLSerializer.serialize(tokens, {:encoding=>'utf-8', 27: :quote_char => "'", 28: :inject_meta_charset => false, 29: :sanitize => true}).gsub(/\A<div xmlns='http:\/\/www.w3.org\/1999\/xhtml'>(.*)<\/div>\Z/m, '\1') 30: rescue REXML::ParseException 31: return "Ill-formed XHTML!" 32: end
# File lib/feed_tools/vendor/html5/tests/test_sanitizer.rb, line 14 14: def sanitize_xhtml stream 15: XHTMLParser.parse_fragment(stream, {:tokenizer => HTMLSanitizer, :encoding => 'utf-8', :lowercase_element_name => false, :lowercase_attr_name => false}).to_s 16: end
# File lib/feed_tools/vendor/html5/tests/test_sanitizer.rb, line 113 113: def test_should_handle_astral_plane_characters 114: input = "<p>𝒵 𝔸</p>" 115: output = "<p>\360\235\222\265 \360\235\224\270</p>" 116: check_sanitization(input, output, output, output) 117: 118: input = "<p><tspan>\360\235\224\270</tspan> a</p>" 119: output = "<p><tspan>\360\235\224\270</tspan> a</p>" 120: check_sanitization(input, output, output, output) 121: end