Skip to content

Commit

Permalink
Hash#slice! was not implemented as I expected.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Feb 20, 2020
1 parent 7aac7bf commit c8e08d2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ cache: bundler

matrix:
include:
- rvm: 2.4
- rvm: 2.5
- rvm: 2.6
- rvm: 2.6
Expand Down
4 changes: 4 additions & 0 deletions lib/trenni/sanitize/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def accept!(mode = ALL)
def [] key
self.tag&.attributes[key]
end

def limit_attributes(keys)
self.tag&.attributes&.select!{|key, value| keys.include?(key)}
end
end

def initialize(output, entities)
Expand Down
6 changes: 4 additions & 2 deletions lib/trenni/sanitize/fragment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@

require_relative 'filter'

require 'set'

module Trenni
module Sanitize
class Fragment < Filter
STANDARD_ATTRIBUTES = ['class', 'style'].freeze
STANDARD_ATTRIBUTES = Set.new(['class', 'style']).freeze

ALLOWED_TAGS = {
'div' => STANDARD_ATTRIBUTES,
Expand All @@ -49,7 +51,7 @@ class Fragment < Filter

def filter(node)
if attributes = ALLOWED_TAGS[node.name]
node.tag.attributes.slice!(*attributes)
node.limit_attributes(attributes)

node.accept!
else
Expand Down
2 changes: 1 addition & 1 deletion trenni-sanitize.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.required_ruby_version = '~> 2.5'
spec.required_ruby_version = '~> 2.4'

spec.add_dependency "trenni", '~> 3.5'

Expand Down

0 comments on commit c8e08d2

Please sign in to comment.