diff --git a/lib/rails/html/scrubbers.rb b/lib/rails/html/scrubbers.rb index 361fa7c..5c91903 100644 --- a/lib/rails/html/scrubbers.rb +++ b/lib/rails/html/scrubbers.rb @@ -108,8 +108,11 @@ def scrub_node(node) def scrub_attributes(node) if @attributes node.attribute_nodes.each do |attr| - attr.remove if scrub_attribute?(attr.name) - scrub_attribute(node, attr) + if scrub_attribute?(attr.name) + attr.remove + else + scrub_attribute(node, attr) + end end scrub_css_attribute(node) diff --git a/test/scrubbers_test.rb b/test/scrubbers_test.rb index 7550d22..2ca888c 100644 --- a/test/scrubbers_test.rb +++ b/test/scrubbers_test.rb @@ -241,6 +241,16 @@ def scrub_attribute(node, attr) end end + def test_does_not_scrub_removed_attributes + @scrubber = TestPermitScrubber.new + + input = "
" + frag = scrub_fragment(input) + assert_equal("
", frag) + + assert_equal([["div", "class"]], @scrubber.instance_variable_get(:@scrub_attribute_args)) + end + def test_does_not_scrub_attributes_of_a_removed_node @scrubber = TestPermitScrubber.new