Class: XmlSanitizer::DefaultPermitScrubber

Inherits:
Loofah::Scrubber
  • Object
show all
Defined in:
lib/xml_sanitizer/default_permit_scrubber.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tags: []) ⇒ DefaultPermitScrubber

Returns a new instance of DefaultPermitScrubber.



7
8
9
10
# File 'lib/xml_sanitizer/default_permit_scrubber.rb', line 7

def initialize(tags: [])
  super
  @tags = tags
end

Instance Attribute Details

#directionObject

Returns the value of attribute direction.



5
6
7
# File 'lib/xml_sanitizer/default_permit_scrubber.rb', line 5

def direction
  @direction
end

#tagsObject

Returns the value of attribute tags.



5
6
7
# File 'lib/xml_sanitizer/default_permit_scrubber.rb', line 5

def tags
  @tags
end

Instance Method Details

#namespace_prefix?(node) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/xml_sanitizer/default_permit_scrubber.rb', line 22

def namespace_prefix?(node)
  !!node&.namespace&.prefix
end

#node_name(node) ⇒ Object



18
19
20
# File 'lib/xml_sanitizer/default_permit_scrubber.rb', line 18

def node_name(node)
  namespace_prefix?(node) ? node_name_with_namespace_prefix(node) : node.name
end

#node_name_with_namespace_prefix(node) ⇒ Object



26
27
28
# File 'lib/xml_sanitizer/default_permit_scrubber.rb', line 26

def node_name_with_namespace_prefix(node)
  "#{node.namespace.prefix}:#{node.name}"
end

#scrub(node) ⇒ Object



12
13
14
15
16
# File 'lib/xml_sanitizer/default_permit_scrubber.rb', line 12

def scrub(node)
  return CONTINUE if skip_node?(node)

  node.remove unless allowed_node?(node)
end