Class: SafeYAML::SyckTagVerifier

Inherits:
Object
  • Object
show all
Defined in:
lib/safe_yaml/syck_tag_verifier.rb

Constant Summary collapse

QUOTE_STYLES =
[:quote1, :quote2]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(whitelist) ⇒ SyckTagVerifier

Returns a new instance of SyckTagVerifier.



7
8
9
10
# File 'lib/safe_yaml/syck_tag_verifier.rb', line 7

def initialize(whitelist)
  @tags = Set.new
  @verifier = SafeYAML::TagVerifier.new(whitelist)
end

Instance Attribute Details

#tagsObject (readonly)

Returns the value of attribute tags.



5
6
7
# File 'lib/safe_yaml/syck_tag_verifier.rb', line 5

def tags
  @tags
end

Instance Method Details

#verify(node) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/safe_yaml/syck_tag_verifier.rb', line 12

def verify(node)
  return unless node.respond_to?(:type_id)
  if !QUOTE_STYLES.include?(node.instance_variable_get(:@style)) && node.value.is_a?(String)
    YAML.check_string_for_symbol!(node.value)
  end
  @verifier.verify_tag!(node.type_id, node.value)

  case node.value
  when Hash
    node.value.each { |k,v| verify(k); verify(v) }
  when Array
    node.value.each { |i| verify(i) }
  end
end