2007-10-13 23:32:04 +02:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
|
|
|
require 'sanitize'
|
|
|
|
|
|
|
|
class SanitizeTest < Test::Unit::TestCase
|
|
|
|
|
2008-05-21 00:02:10 +02:00
|
|
|
include Sanitize
|
|
|
|
|
2007-10-13 23:32:04 +02:00
|
|
|
def setup
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def rexml_doc(string)
|
|
|
|
REXML::Document.new(
|
|
|
|
"<div xmlns='http://www.w3.org/1999/xhtml'>#{string}</div>")
|
|
|
|
end
|
|
|
|
|
|
|
|
def my_rex(string)
|
|
|
|
sanitize_rexml(rexml_doc(string)).gsub(/\A<div xmlns="http:\/\/www.w3.org\/1999\/xhtml">(.*)<\/div>\Z/m, '\1')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_sanitize_named_entities
|
|
|
|
input = '<p>Greek φ, double-struck 𝔸, numeric 𝔸 ⁗</p>'
|
|
|
|
output = "<p>Greek \317\225, double-struck \360\235\224\270, numeric \360\235\224\270 \342\201\227</p>"
|
|
|
|
output2 = "<p>Greek \317\225, double-struck \360\235\224\270, numeric 𝔸 ⁗</p>"
|
|
|
|
assert_equal(output, sanitize_xhtml(input))
|
|
|
|
assert_equal(output, sanitize_html(input))
|
|
|
|
assert_equal(output, my_rex(input))
|
|
|
|
assert_equal(output2, input.to_utf8)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|