Skip to content

Commit b4efdad

Browse files
committed
Do not scrub removed attributes
This should improve performance by eliminating needless sanitization of attributes that are already removed.
1 parent a2edfdc commit b4efdad

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Diff for: lib/rails/html/scrubbers.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,11 @@ def scrub_node(node)
108108
def scrub_attributes(node)
109109
if @attributes
110110
node.attribute_nodes.each do |attr|
111-
attr.remove if scrub_attribute?(attr.name)
112-
scrub_attribute(node, attr)
111+
if scrub_attribute?(attr.name)
112+
attr.remove
113+
else
114+
scrub_attribute(node, attr)
115+
end
113116
end
114117

115118
scrub_css_attribute(node)

Diff for: test/scrubbers_test.rb

+10
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,16 @@ def scrub_attribute(node, attr)
249249
end
250250
end
251251

252+
def test_does_not_scrub_removed_attributes
253+
@scrubber = TestPermitScrubber.new
254+
255+
input = "<div class='foo' href='bar'></div>"
256+
frag = scrub_fragment(input)
257+
assert_equal("<div class=\"foo\"></div>", frag)
258+
259+
assert_equal([["div", "class"]], @scrubber.instance_variable_get(:@scrub_attribute_args))
260+
end
261+
252262
def test_does_not_scrub_attributes_of_a_removed_node
253263
@scrubber = TestPermitScrubber.new
254264

0 commit comments

Comments
 (0)