Class: SafeYAML::TagVerifier

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

Instance Method Summary collapse

Constructor Details

#initialize(whitelist) ⇒ TagVerifier

Returns a new instance of TagVerifier.



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

def initialize(whitelist)
  @whitelist = whitelist
  @seen = Set.new
end

Instance Method Details

#verify_tag!(tag, value) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/safe_yaml/tag_verifier.rb', line 10

def verify_tag!(tag, value)
  return if !tag || @seen.include?(tag)

  case @whitelist.check(tag, value)
  when :cacheable
    @seen << tag
  when :allowed
    # in the whitelist, but can't be cached (because it called a proc for yes/no)
  else
    raise SafeYAML::UnsafeTagError.new("YAML tag is not whitelisted: #{tag} #{value.inspect}")
  end
end