Module: YAML

Defined in:
lib/safe_yaml/syck_hack.rb,
lib/safe_yaml.rb

Overview

Hack to JRuby 1.8’s YAML Parser Yecht

This file is always loaded AFTER either syck or psych are already loaded. It then looks at what constants are available and creates a consistent view on all rubys.

Taken from rubygems and modified. See github.com/rubygems/rubygems/blob/master/lib/rubygems/syck_hack.rb

Constant Summary collapse

Syck =

JRuby’s “Syck” is called “Yecht”

YAML::Yecht

Class Method Summary collapse

Class Method Details

.load_file_with_options(file, options = {}) ⇒ Object Also known as: load_file



19
20
21
22
23
24
25
26
# File 'lib/safe_yaml.rb', line 19

def self.load_file_with_options(file, options={})
  safe_mode = safe_mode_from_options("load_file", options)
  if safe_mode == :safe
    safe_load_file(file, options_for_safe_load(options))
  else
    unsafe_load_file(file)
  end
end

.load_with_options(yaml, *original_arguments) ⇒ Object Also known as: load



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/safe_yaml.rb', line 4

def self.load_with_options(yaml, *original_arguments)
  filename, options = filename_and_options_from_arguments(original_arguments)
  safe_mode = safe_mode_from_options("load", options)
  arguments = [yaml]

  if safe_mode == :safe
    arguments << filename if SafeYAML::YAML_ENGINE == "psych"
    arguments << options_for_safe_load(options)
    safe_load(*arguments)
  else
    arguments << filename if SafeYAML::MULTI_ARGUMENT_YAML_LOAD
    unsafe_load(*arguments)
  end
end

.safe_load(*args) ⇒ Object



28
29
30
# File 'lib/safe_yaml.rb', line 28

def self.safe_load(*args)
  SafeYAML.load(*args)
end

.safe_load_file(*args) ⇒ Object



32
33
34
# File 'lib/safe_yaml.rb', line 32

def self.safe_load_file(*args)
  SafeYAML.load_file(*args)
end

.unsafe_load_file(filename) ⇒ Object



37
38
39
40
# File 'lib/safe_yaml.rb', line 37

def self.unsafe_load_file(filename)
  # https://github.com/tenderlove/psych/blob/v1.3.2/lib/psych.rb#L296-298
  File.open(filename, 'r:bom|utf-8') { |f| self.unsafe_load(f, filename) }
end