Parent

Included Modules

Class/Module Index [+]

Quicksearch

SanitizeTest

Public Instance Methods

check_sanitization(input, htmloutput, xhtmloutput, rexmloutput) click to toggle source
# File lib/feed_tools/vendor/html5/tests/test_sanitizer.rb, line 34
def check_sanitization(input, htmloutput, xhtmloutput, rexmloutput)
  assert_equal htmloutput, sanitize_html(input)
  assert_equal xhtmloutput, sanitize_xhtml(input)
  assert_equal rexmloutput, sanitize_rexml(input)
end
sanitize_html(stream) click to toggle source
# File lib/feed_tools/vendor/html5/tests/test_sanitizer.rb, line 18
def sanitize_html stream
  HTMLParser.parse_fragment(stream, {:tokenizer => HTMLSanitizer, :encoding => 'utf-8', :lowercase_element_name => false, :lowercase_attr_name => false}).to_s
end
sanitize_rexml(stream) click to toggle source
# File lib/feed_tools/vendor/html5/tests/test_sanitizer.rb, line 22
def sanitize_rexml stream
  require 'rexml/document'
  doc = REXML::Document.new("<div xmlns='http://www.w3.org/1999/xhtml'>#{stream}</div>")
  tokens = TreeWalkers.get_tree_walker('rexml').new(doc)
  XHTMLSerializer.serialize(tokens, {:encoding=>'utf-8',
    :quote_char => "'",
    :inject_meta_charset => false,
    :sanitize => true}).gsub(/\A<div xmlns='http:\/\/www.w3.org\/1999\/xhtml'>(.*)<\/div>\Z/, '\1')
rescue REXML::ParseException
  return "Ill-formed XHTML!"
end
sanitize_xhtml(stream) click to toggle source
# File lib/feed_tools/vendor/html5/tests/test_sanitizer.rb, line 14
def sanitize_xhtml stream
  XHTMLParser.parse_fragment(stream, {:tokenizer => HTMLSanitizer, :encoding => 'utf-8', :lowercase_element_name => false, :lowercase_attr_name => false}).to_s
end
test_should_handle_astral_plane_characters() click to toggle source
# File lib/feed_tools/vendor/html5/tests/test_sanitizer.rb, line 113
def test_should_handle_astral_plane_characters
  input = "<p>&#x1d4b5; &#x1d538;</p>"
  output = "<p>\3360\2235\2222\2265 \3360\2235\2224\2270</p>"
  check_sanitization(input, output, output, output)

  input = "<p><tspan>\3360\2235\2224\2270</tspan> a</p>"
  output = "<p><tspan>\3360\2235\2224\2270</tspan> a</p>"
  check_sanitization(input, output, output, output)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.