Module: SafeYAML

### Home Classes Methods

### In Files

- lib/safe_yaml.rb
- lib/safe_yaml/deep.rb
- lib/safe_yaml/parse/date.rb
- lib/safe_yaml/parse/hexadecimal.rb
- lib/safe_yaml/parse/sexagesimal.rb
- lib/safe_yaml/psych_handler.rb
- lib/safe_yaml/psych_resolver.rb
- lib/safe_yaml/resolver.rb
- lib/safe_yaml/safe_to_ruby_visitor.rb
- lib/safe_yaml/syck_resolver.rb
- lib/safe_yaml/transform.rb
- lib/safe_yaml/transform/to_boolean.rb
- lib/safe_yaml/transform/to_date.rb
- lib/safe_yaml/transform/to_float.rb
- lib/safe_yaml/transform/to_integer.rb
- lib/safe_yaml/transform/to_nil.rb
- lib/safe_yaml/transform/to_symbol.rb
- lib/safe_yaml/transform/transformation_map.rb
- lib/safe_yaml/version.rb

### Namespace

- CLASS SafeYAML::Deep
- CLASS SafeYAML::Parse
- CLASS SafeYAML::PsychHandler
- CLASS SafeYAML::PsychResolver
- CLASS SafeYAML::Resolver
- CLASS SafeYAML::SafeToRubyVisitor
- CLASS SafeYAML::SyckResolver
- CLASS SafeYAML::Transform

### Methods

- #predefined_tags
- #restore_defaults!
- #tag_is_explicitly_trusted?
- #tag_safety_check!
- #whitelist!
- #whitelist_class!

### Class/Module Index

Quicksearch

- SafeYAML
- SafeYAML::Deep
- SafeYAML::Parse
- SafeYAML::Parse::Date
- SafeYAML::Parse::Hexadecimal
- SafeYAML::Parse::Sexagesimal
- SafeYAML::PsychHandler
- SafeYAML::PsychResolver
- SafeYAML::Resolver
- SafeYAML::SafeToRubyVisitor
- SafeYAML::SyckResolver
- SafeYAML::Transform
- SafeYAML::Transform::ToBoolean
- SafeYAML::Transform::ToDate
- SafeYAML::Transform::ToFloat
- SafeYAML::Transform::ToInteger
- SafeYAML::Transform::ToNil
- SafeYAML::Transform::ToSymbol
- SafeYAML::Transform::TransformationMap
- SafeYAML::Transform::TransformationMap::CaseAgnosticMap
- SafeYAML::Transform::TransformationMap::ClassMethods
- Object
- YAML

No matching classes.

# SafeYAML

This needs to be defined up front in case any internal classes need to base their behavior off of this.

### Constants

DEFAULT_OPTIONS
MULTI_ARGUMENT_YAML_LOAD
OPTIONS
TRUSTED_TAGS
VERSION
YAML_ENGINE

### Public Instance Methods

predefined_tags() click to toggle source

    # File lib/safe_yaml.rb, line 81
    def predefined_tags
      if @predefined_tags.nil?
        @predefined_tags = {}

        if YAML_ENGINE == "syck"
          YAML.tagged_classes.each do |tag, klass|
            @predefined_tags[klass] = tag
          end

        else
          # Special tags appear to be hard-coded in Psych:
          # https://github.com/tenderlove/psych/blob/v1.3.4/lib/psych/visitors/to_ruby.rb
          # Fortunately, there aren't many that SafeYAML doesn't already support.
          @predefined_tags.merge!({
            Exception => "!ruby/exception",
            Range     => "!ruby/range",
            Regexp    => "!ruby/regexp",
          })
        end
      end

      @predefined_tags
    end

restore_defaults!() click to toggle source

    # File lib/safe_yaml.rb, line 40
    def restore_defaults!
      OPTIONS.clear.merge!(Deep.copy(DEFAULT_OPTIONS))
    end

tag_is_explicitly_trusted?(tag) click to toggle source

    # File lib/safe_yaml.rb, line 106
    def tag_is_explicitly_trusted?(tag)
      false
    end

tag_safety_check!(tag, options) click to toggle source

    # File lib/safe_yaml.rb, line 44
    def tag_safety_check!(tag, options)
      return if tag.nil? || tag == "!"
      if options[:raise_on_unknown_tag] && !options[:whitelisted_tags].include?(tag) && !tag_is_explicitly_trusted?(tag)
        raise "Unknown YAML tag '#{tag}'"
      end
    end

whitelist!(*classes) click to toggle source

    # File lib/safe_yaml.rb, line 51
    def whitelist!(*classes)
      classes.each do |klass|
        whitelist_class!(klass)
      end
    end

whitelist_class!(klass) click to toggle source

    # File lib/safe_yaml.rb, line 57
    def whitelist_class!(klass)
      raise "#{klass} not a Class" unless klass.is_a?(::Class)

      klass_name = klass.name
      raise "#{klass} cannot be anonymous" if klass_name.nil? || klass_name.empty?

      # Whitelist any built-in YAML tags supplied by Syck or Psych.
      predefined_tag = predefined_tags[klass]
      if predefined_tag
        OPTIONS[:whitelisted_tags] << predefined_tag
        return
      end

      # Exception is exceptional (har har).
      tag_class  = klass < Exception ? "exception" : "object"

      tag_prefix = case YAML_ENGINE
                   when "psych" then "!ruby/#{tag_class}"
                   when "syck"  then "tag:ruby.yaml.org,2002:#{tag_class}"
                   else raise "unknown YAML_ENGINE #{YAML_ENGINE}"
                   end
      OPTIONS[:whitelisted_tags] << "#{tag_prefix}:#{klass_name}"
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.