Skip to content

Commit

Permalink
Fix various rubocop offences
Browse files Browse the repository at this point in the history
  • Loading branch information
dedene committed Nov 28, 2023
1 parent 8174086 commit a5c388e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 3 additions & 4 deletions lib/loofah/html5/safelist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ module SafeList
"use",
])


ACCEPTABLE_EMPTY_ATTRIBUTES = {
"*" => Set.new([
"hidden",
Expand Down Expand Up @@ -265,7 +264,7 @@ module SafeList
"details" => Set.new([
"open",
]),
"fieldset" => Set.new([
"fieldset" => Set.new([
"disabled",
]),
"form" => Set.new([
Expand Down Expand Up @@ -302,7 +301,7 @@ module SafeList
"ol" => Set.new([
"reversed",
]),
"optgroup" => Set.new([
"optgroup" => Set.new([
"disabled",
]),
"option" => Set.new([
Expand Down Expand Up @@ -438,7 +437,7 @@ module SafeList
"vspace",
"width",
"xml:lang",
].concat(ACCEPTABLE_EMPTY_ATTRIBUTES.values.flat_map(&:to_a)))
].concat(ACCEPTABLE_EMPTY_ATTRIBUTES.values.flat_map(&:to_a)))

MATHML_ATTRIBUTES = Set.new([
"actiontype",
Expand Down
8 changes: 5 additions & 3 deletions lib/loofah/html5/scrub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ def scrub_attributes(node)
scrub_css_attribute(node)

node.attribute_nodes.each do |attr_node|
if attr_node.value !~ /[^[:space:]]/ && attr_node.name !~ DATA_ATTRIBUTE_NAME && !SafeList::ACCEPTABLE_EMPTY_ATTRIBUTES["*"].include?(attr_node.name) && !SafeList::ACCEPTABLE_EMPTY_ATTRIBUTES[node.name]&.include?(attr_node.name)
node.remove_attribute(attr_node.name)
end
next if attr_node.value =~ /[^[:space:]]/ || attr_node.name =~ DATA_ATTRIBUTE_NAME ||
SafeList::ACCEPTABLE_EMPTY_ATTRIBUTES["*"].include?(attr_node.name) ||
SafeList::ACCEPTABLE_EMPTY_ATTRIBUTES[node.name]&.include?(attr_node.name)

node.remove_attribute(attr_node.name)
end

force_correct_attribute_escaping!(node)
Expand Down

0 comments on commit a5c388e

Please sign in to comment.