From a5bd819f3ef13d5d4595106557c26169df2ef3a0 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Wed, 9 Oct 2019 15:35:06 -0400 Subject: [PATCH] rufo formatting --- lib/loofah/html5/safelist.rb | 3 +-- test/integration/test_ad_hoc.rb | 36 ++++++++++++++++----------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/lib/loofah/html5/safelist.rb b/lib/loofah/html5/safelist.rb index f7d38f26..8abd922e 100644 --- a/lib/loofah/html5/safelist.rb +++ b/lib/loofah/html5/safelist.rb @@ -1,4 +1,4 @@ -require 'set' +require "set" module Loofah module HTML5 # :nodoc: @@ -45,7 +45,6 @@ module HTML5 # :nodoc: # # module SafeList - ACCEPTABLE_ELEMENTS = Set.new([ "a", "abbr", diff --git a/test/integration/test_ad_hoc.rb b/test/integration/test_ad_hoc.rb index ac1e28cc..16fccbbf 100644 --- a/test/integration/test_ad_hoc.rb +++ b/test/integration/test_ad_hoc.rb @@ -1,7 +1,6 @@ require "helper" class IntegrationTestAdHoc < Loofah::TestCase - context "blank input string" do context "fragment" do it "return a blank string" do @@ -33,9 +32,9 @@ def test_removal_of_illegal_attribute html = "

" sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :escape).to_xml) node = sane.xpath("//p").first - assert node.attributes['class'] - assert node.attributes['abbr'] - assert_nil node.attributes['foo'] + assert node.attributes["class"] + assert node.attributes["abbr"] + assert_nil node.attributes["foo"] end def test_removal_of_illegal_url_in_href @@ -45,14 +44,14 @@ def test_removal_of_illegal_url_in_href HTML sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :escape).to_xml) nodes = sane.xpath("//a") - assert_nil nodes.first.attributes['href'] - assert nodes.last.attributes['href'] + assert_nil nodes.first.attributes["href"] + assert nodes.last.attributes["href"] end def test_css_sanitization html = "

" sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :escape).to_xml) - assert_match %r/#000/, sane.inner_html + assert_match %r/#000/, sane.inner_html refute_match %r/foo\.com/, sane.inner_html end @@ -75,7 +74,7 @@ def test_fragment_with_text_nodes_leading_and_trailing 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","") + assert_equal "

safe

description", whitewashed.gsub("\n", "") end def test_fragment_whitewash_on_microsofty_markup @@ -86,11 +85,11 @@ def test_fragment_whitewash_on_microsofty_markup 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 + 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 + assert_equal "", Loofah.scrub_document("", :prune).text end def test_nested_script_cdata_tags_should_be_scrubbed @@ -145,21 +144,20 @@ def test_dont_remove_whitespace_between_tags # # https://git.gnome.org/browse/libxml2/tree/HTMLtree.c?h=v2.9.2#n714 # - {tag: "a", attr: "href"}, - {tag: "div", attr: "href"}, - {tag: "a", attr: "action"}, - {tag: "div", attr: "action"}, - {tag: "a", attr: "src"}, - {tag: "div", attr: "src"}, - {tag: "a", attr: "name"}, + { tag: "a", attr: "href" }, + { tag: "div", attr: "href" }, + { tag: "a", attr: "action" }, + { tag: "div", attr: "action" }, + { tag: "a", attr: "src" }, + { tag: "div", attr: "src" }, + { tag: "a", attr: "name" }, # # note that div+name is _not_ affected by the libxml2 issue. # but we test it anyway to ensure our logic isn't modifying # attributes that don't need modifying. # - {tag: "div", attr: "name", unescaped: true}, + { tag: "div", attr: "name", unescaped: true }, ].each do |config| - define_method "test_uri_escaping_of_#{config[:attr]}_attr_in_#{config[:tag]}_tag" do html = %{<#{config[:tag]} #{config[:attr]}='example.com'>test}