require "helper"
class IntegrationTestAdHoc < Loofah::TestCase
context "blank input string" do
context "fragment" do
it "return a blank string" do
assert_equal "", Loofah.scrub_fragment("", :prune).to_s
end
end
context "document" do
it "return a blank string" do
assert_equal "", Loofah.scrub_document("", :prune).root.to_s
end
end
end
context "tests" do
MSWORD_HTML = File.read(File.join(File.dirname(__FILE__), "..", "assets", "msword.html")).freeze
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 def test_fragment_whitewash_on_microsofty_markup whitewashed = Loofah.fragment(MSWORD_HTML).scrub!(:whitewash) assert_equal "Foo BOLD
", whitewashed.to_s.strip end def test_document_whitewash_on_microsofty_markup whitewashed = Loofah.document(MSWORD_HTML).scrub!(:whitewash) assert_match %r(Foo BOLD
), whitewashed.to_s 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_nested_script_cdata_tags_should_be_scrubbed html = "" stripped = Loofah.fragment(html).scrub!(:strip) assert_empty stripped.xpath("//script") refute_match("