require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helper'))
class TestAdHoc < Test::Unit::TestCase
context "blank input string" do
context "fragment" do
should "return a blank string" do
assert_equal "", Loofah.scrub_fragment("", :prune).to_s
end
end
context "document" do
should "return a blank string" do
assert_equal "", Loofah.scrub_document("", :prune).root.to_s
end
end
end
def test_removal_of_illegal_tag
html = <<-HTML
following this there should be no jim tag
This fragment is in a p.
", Loofah.scrub_fragment("This fragment is in a p.
", :escape).to_xml end def test_fragment_in_p_tag_plus_stuff assert_equal "This fragment is in a p.
foobar", Loofah.scrub_fragment("This fragment is in a p.
foobar", :escape).to_xml end def test_fragment_with_text_nodes_leading_and_trailing assert_equal "textfragment
text", Loofah.scrub_fragment("textfragment
text", :escape).to_xml end def test_whitewash_on_fragment html = "safe description" whitewashed = Loofah.scrub_document(html, :whitewash).xpath("/html/body/*").to_s assert_equal "safe
description", whitewashed.gsub("\n","") end MSWORD_HTML = <<-EOHTMLFoo BOLD
Foo BOLD
", whitewashed.to_s end def test_document_whitewash_on_microsofty_markup whitewashed = Loofah.document(MSWORD_HTML).scrub!(:whitewash) assert_contains whitewashed.to_s, %r(Foo BOLD
) assert_equal "Foo BOLD
", whitewashed.xpath("/html/body/*").to_s end def test_return_empty_string_when_nothing_left assert_equal "", Loofah.scrub_document('', :prune).text end def test_removal_of_all_tags html = <<-HTML What's up doc? HTML stripped = Loofah.scrub_document(html, :prune).text assert_equal %Q(What\'s up doc?).strip, stripped.strip end def test_dont_remove_whitespace html = "Foo\nBar" assert_equal html, Loofah.scrub_document(html, :prune).text end def test_dont_remove_whitespace_between_tags html = "Foo
\nBar
" assert_equal "Foo\nBar", Loofah.scrub_document(html, :prune).text end end