require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
class TestDeprecatedBasic < Test::Unit::TestCase
def test_empty_string
assert_equal "", Loofah.sanitize("")
end
def test_removal_of_illegal_tag
html = <<-HTML
following this there should be no jim tag
jim
was there?
HTML
sane = Nokogiri::HTML(Loofah.sanitize(html))
assert sane.xpath("//jim").empty?
end
def test_removal_of_illegal_attribute
html = "
"
sane = Nokogiri::HTML(Loofah.sanitize(html))
node = sane.xpath("//p").first
assert node.attributes['class']
assert node.attributes['abbr']
assert_nil node.attributes['foo']
end
def test_removal_of_illegal_url_in_href
html = <<-HTML
this link should have its href removed because of illegal url
this link should be fine
HTML
sane = Nokogiri::HTML(Loofah.sanitize(html))
nodes = sane.xpath("//a")
assert_nil nodes.first.attributes['href']
assert nodes.last.attributes['href']
end
def test_css_sanitization
html = ""
sane = Nokogiri::HTML(Loofah.sanitize(html))
assert_match(/#000/, sane.inner_html)
assert_no_match(/foo\.com/, sane.inner_html)
end
def test_fragment_with_no_tags
assert_equal "This fragment has no tags.", Loofah.sanitize("This fragment has no tags.")
end
def test_fragment_in_p_tag
assert_equal "This fragment is in a p.
", Loofah.sanitize("This fragment is in a p.
")
end
def test_fragment_in_p_tag_plus_stuff
assert_equal "This fragment is in a p.
foobar", Loofah.sanitize("This fragment is in a p.
foobar")
end
def test_fragment_with_text_nodes_leading_and_trailing
assert_equal "textfragment
text", Loofah.sanitize("textfragment
text")
end
def test_whitewash_on_fragment
html = "safe description"
whitewashed = Loofah.whitewash_document(html)
assert_equal "safe
description", whitewashed.gsub("\n","")
end
end