puppet 2.7.21 → 2.7.22
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of puppet might be problematic. Click here for more details.
- data/CHANGELOG +14 -0
- data/Gemfile.lock +2 -2
- data/ext/build_defaults.yaml +2 -3
- data/ext/debian/control +1 -1
- data/ext/packaging/README.md +496 -8
- data/ext/packaging/spec/tasks/00_utils_spec.rb +7 -7
- data/ext/packaging/spec/tasks/build_object_spec.rb +3 -0
- data/ext/packaging/tasks/00_utils.rake +2 -2
- data/ext/packaging/tasks/10_setupvars.rake +8 -1
- data/ext/packaging/tasks/build.rake +2 -0
- data/ext/packaging/tasks/deb_repos.rake +48 -15
- data/ext/packaging/tasks/jenkins.rake +30 -2
- data/ext/packaging/tasks/mock.rake +3 -2
- data/ext/packaging/tasks/pe_remote.rake +1 -1
- data/ext/packaging/tasks/pe_ship.rake +4 -5
- data/ext/packaging/tasks/pe_sign.rake +8 -0
- data/ext/packaging/tasks/pe_sles.rake +8 -7
- data/ext/packaging/tasks/pre_tasks.rake +0 -0
- data/ext/packaging/tasks/retrieve.rake +11 -1
- data/ext/packaging/tasks/rpm_repos.rake +71 -49
- data/ext/packaging/tasks/ship.rake +14 -2
- data/ext/packaging/tasks/sign.rake +9 -3
- data/ext/packaging/tasks/tar.rake +5 -0
- data/ext/packaging/tasks/vendor_gems.rake +110 -0
- data/install.rb +1 -1
- data/lib/puppet.rb +11 -0
- data/lib/puppet/indirector/report/processor.rb +1 -1
- data/lib/puppet/indirector/report/rest.rb +7 -0
- data/lib/puppet/indirector/resource/rest.rb +9 -0
- data/lib/puppet/indirector/rest.rb +81 -47
- data/lib/puppet/indirector/run/rest.rb +6 -0
- data/lib/puppet/network/formats.rb +20 -10
- data/lib/puppet/network/http/handler.rb +1 -1
- data/lib/puppet/node.rb +25 -0
- data/lib/puppet/node/facts.rb +23 -4
- data/lib/puppet/resource.rb +2 -4
- data/lib/puppet/resource/status.rb +28 -0
- data/lib/puppet/run.rb +24 -2
- data/lib/puppet/status.rb +6 -2
- data/lib/puppet/transaction/event.rb +19 -0
- data/lib/puppet/transaction/report.rb +39 -0
- data/lib/puppet/util/log.rb +19 -0
- data/lib/puppet/util/metric.rb +6 -0
- data/lib/puppet/util/monkey_patches.rb +0 -16
- data/lib/puppet/vendor.rb +55 -0
- data/lib/puppet/vendor/load_safe_yaml.rb +1 -0
- data/lib/puppet/vendor/require_vendored.rb +4 -0
- data/lib/puppet/vendor/safe_yaml/CHANGES.md +104 -0
- data/lib/puppet/vendor/safe_yaml/Gemfile +11 -0
- data/lib/puppet/vendor/safe_yaml/LICENSE.txt +22 -0
- data/lib/puppet/vendor/safe_yaml/README.md +179 -0
- data/lib/puppet/vendor/safe_yaml/Rakefile +6 -0
- data/lib/puppet/vendor/safe_yaml/lib/safe_yaml.rb +253 -0
- data/lib/puppet/vendor/safe_yaml/lib/safe_yaml/deep.rb +34 -0
- data/lib/puppet/vendor/safe_yaml/lib/safe_yaml/parse/date.rb +27 -0
- data/lib/puppet/vendor/safe_yaml/lib/safe_yaml/parse/hexadecimal.rb +12 -0
- data/lib/puppet/vendor/safe_yaml/lib/safe_yaml/parse/sexagesimal.rb +26 -0
- data/lib/puppet/vendor/safe_yaml/lib/safe_yaml/psych_handler.rb +92 -0
- data/lib/puppet/vendor/safe_yaml/lib/safe_yaml/psych_resolver.rb +52 -0
- data/lib/puppet/vendor/safe_yaml/lib/safe_yaml/resolver.rb +94 -0
- data/lib/puppet/vendor/safe_yaml/lib/safe_yaml/safe_to_ruby_visitor.rb +17 -0
- data/lib/puppet/vendor/safe_yaml/lib/safe_yaml/syck_hack.rb +36 -0
- data/lib/puppet/vendor/safe_yaml/lib/safe_yaml/syck_node_monkeypatch.rb +43 -0
- data/lib/puppet/vendor/safe_yaml/lib/safe_yaml/syck_resolver.rb +38 -0
- data/lib/puppet/vendor/safe_yaml/lib/safe_yaml/transform.rb +41 -0
- data/lib/puppet/vendor/safe_yaml/lib/safe_yaml/transform/to_boolean.rb +21 -0
- data/lib/puppet/vendor/safe_yaml/lib/safe_yaml/transform/to_date.rb +11 -0
- data/lib/puppet/vendor/safe_yaml/lib/safe_yaml/transform/to_float.rb +33 -0
- data/lib/puppet/vendor/safe_yaml/lib/safe_yaml/transform/to_integer.rb +25 -0
- data/lib/puppet/vendor/safe_yaml/lib/safe_yaml/transform/to_nil.rb +18 -0
- data/lib/puppet/vendor/safe_yaml/lib/safe_yaml/transform/to_symbol.rb +13 -0
- data/lib/puppet/vendor/safe_yaml/lib/safe_yaml/transform/transformation_map.rb +47 -0
- data/lib/puppet/vendor/safe_yaml/lib/safe_yaml/version.rb +3 -0
- data/lib/puppet/vendor/safe_yaml/run_specs_all_ruby_versions.sh +21 -0
- data/lib/puppet/vendor/safe_yaml/safe_yaml.gemspec +18 -0
- data/lib/puppet/vendor/safe_yaml/spec/exploit.1.9.2.yaml +2 -0
- data/lib/puppet/vendor/safe_yaml/spec/exploit.1.9.3.yaml +2 -0
- data/lib/puppet/vendor/safe_yaml/spec/psych_resolver_spec.rb +10 -0
- data/lib/puppet/vendor/safe_yaml/spec/resolver_specs.rb +250 -0
- data/lib/puppet/vendor/safe_yaml/spec/safe_yaml_spec.rb +702 -0
- data/lib/puppet/vendor/safe_yaml/spec/spec_helper.rb +18 -0
- data/lib/puppet/vendor/safe_yaml/spec/support/exploitable_back_door.rb +29 -0
- data/lib/puppet/vendor/safe_yaml/spec/syck_resolver_spec.rb +10 -0
- data/lib/puppet/vendor/safe_yaml/spec/transform/base64_spec.rb +11 -0
- data/lib/puppet/vendor/safe_yaml/spec/transform/to_date_spec.rb +34 -0
- data/lib/puppet/vendor/safe_yaml/spec/transform/to_float_spec.rb +42 -0
- data/lib/puppet/vendor/safe_yaml/spec/transform/to_integer_spec.rb +59 -0
- data/lib/puppet/vendor/safe_yaml/spec/transform/to_symbol_spec.rb +49 -0
- data/lib/puppet/version.rb +1 -1
- data/spec/lib/puppet_spec/matchers.rb +8 -0
- data/spec/unit/file_serving/metadata_spec.rb +20 -28
- data/spec/unit/indirector/report/rest_spec.rb +41 -0
- data/spec/unit/indirector/rest_spec.rb +314 -339
- data/spec/unit/network/formats_spec.rb +36 -27
- data/spec/unit/network/http/handler_spec.rb +3 -12
- data/spec/unit/node_spec.rb +81 -0
- data/spec/unit/resource_spec.rb +5 -35
- data/spec/unit/run_spec.rb +22 -8
- data/spec/unit/status_spec.rb +6 -0
- data/test/network/handler/report.rb +0 -36
- metadata +148 -102
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
module SafeYAML
|
4
|
+
class Transform
|
5
|
+
TRANSFORMERS = [
|
6
|
+
Transform::ToSymbol.new,
|
7
|
+
Transform::ToInteger.new,
|
8
|
+
Transform::ToFloat.new,
|
9
|
+
Transform::ToNil.new,
|
10
|
+
Transform::ToBoolean.new,
|
11
|
+
Transform::ToDate.new
|
12
|
+
]
|
13
|
+
|
14
|
+
def self.to_guessed_type(value, quoted=false, options=nil)
|
15
|
+
return value if quoted
|
16
|
+
|
17
|
+
if value.is_a?(String)
|
18
|
+
TRANSFORMERS.each do |transformer|
|
19
|
+
success, transformed_value = transformer.method(:transform?).arity == 1 ?
|
20
|
+
transformer.transform?(value) :
|
21
|
+
transformer.transform?(value, options)
|
22
|
+
|
23
|
+
return transformed_value if success
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
value
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.to_proper_type(value, quoted=false, tag=nil, options=nil)
|
31
|
+
case tag
|
32
|
+
when "tag:yaml.org,2002:binary", "x-private:binary", "!binary"
|
33
|
+
decoded = Base64.decode64(value)
|
34
|
+
decoded = decoded.force_encoding(value.encoding) if decoded.respond_to?(:force_encoding)
|
35
|
+
decoded
|
36
|
+
else
|
37
|
+
self.to_guessed_type(value, quoted, options)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module SafeYAML
|
2
|
+
class Transform
|
3
|
+
class ToBoolean
|
4
|
+
include TransformationMap
|
5
|
+
|
6
|
+
set_predefined_values({
|
7
|
+
"yes" => true,
|
8
|
+
"on" => true,
|
9
|
+
"true" => true,
|
10
|
+
"no" => false,
|
11
|
+
"off" => false,
|
12
|
+
"false" => false
|
13
|
+
})
|
14
|
+
|
15
|
+
def transform?(value)
|
16
|
+
return false if value.length > 5
|
17
|
+
return PREDEFINED_VALUES.include?(value), PREDEFINED_VALUES[value]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module SafeYAML
|
2
|
+
class Transform
|
3
|
+
class ToDate
|
4
|
+
def transform?(value)
|
5
|
+
return true, Date.parse(value) if Parse::Date::DATE_MATCHER.match(value)
|
6
|
+
return true, Parse::Date.value(value) if Parse::Date::TIME_MATCHER.match(value)
|
7
|
+
false
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module SafeYAML
|
2
|
+
class Transform
|
3
|
+
class ToFloat
|
4
|
+
Infinity = 1.0 / 0.0
|
5
|
+
NaN = 0.0 / 0.0
|
6
|
+
|
7
|
+
PREDEFINED_VALUES = {
|
8
|
+
".inf" => Infinity,
|
9
|
+
".Inf" => Infinity,
|
10
|
+
".INF" => Infinity,
|
11
|
+
"-.inf" => -Infinity,
|
12
|
+
"-.Inf" => -Infinity,
|
13
|
+
"-.INF" => -Infinity,
|
14
|
+
".nan" => NaN,
|
15
|
+
".NaN" => NaN,
|
16
|
+
".NAN" => NaN,
|
17
|
+
}.freeze
|
18
|
+
|
19
|
+
MATCHER = /\A[-+]?(?:\d[\d_]*)?\.[\d_]+(?:[eE][-+][\d]+)?\Z/.freeze
|
20
|
+
|
21
|
+
def transform?(value)
|
22
|
+
return true, Float(value) if MATCHER.match(value)
|
23
|
+
try_edge_cases?(value)
|
24
|
+
end
|
25
|
+
|
26
|
+
def try_edge_cases?(value)
|
27
|
+
return true, PREDEFINED_VALUES[value] if PREDEFINED_VALUES.include?(value)
|
28
|
+
return true, Parse::Sexagesimal.value(value) if Parse::Sexagesimal::FLOAT_MATCHER.match(value)
|
29
|
+
return false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module SafeYAML
|
2
|
+
class Transform
|
3
|
+
class ToInteger
|
4
|
+
MATCHERS = Deep.freeze([
|
5
|
+
/\A[-+]?(0|([1-9][0-9_,]*))\Z/, # decimal
|
6
|
+
/\A0[0-7]+\Z/, # octal
|
7
|
+
/\A0x[0-9a-f]+\Z/i, # hexadecimal
|
8
|
+
/\A0b[01_]+\Z/ # binary
|
9
|
+
])
|
10
|
+
|
11
|
+
def transform?(value)
|
12
|
+
MATCHERS.each do |matcher|
|
13
|
+
return true, Integer(value.gsub(",", "")) if matcher.match(value)
|
14
|
+
end
|
15
|
+
try_edge_cases?(value)
|
16
|
+
end
|
17
|
+
|
18
|
+
def try_edge_cases?(value)
|
19
|
+
return true, Parse::Hexadecimal.value(value) if Parse::Hexadecimal::MATCHER.match(value)
|
20
|
+
return true, Parse::Sexagesimal.value(value) if Parse::Sexagesimal::INTEGER_MATCHER.match(value)
|
21
|
+
return false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module SafeYAML
|
2
|
+
class Transform
|
3
|
+
class ToNil
|
4
|
+
include TransformationMap
|
5
|
+
|
6
|
+
set_predefined_values({
|
7
|
+
"" => nil,
|
8
|
+
"~" => nil,
|
9
|
+
"null" => nil,
|
10
|
+
})
|
11
|
+
|
12
|
+
def transform?(value)
|
13
|
+
return false if value.length > 4
|
14
|
+
return PREDEFINED_VALUES.include?(value), PREDEFINED_VALUES[value]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module SafeYAML
|
2
|
+
class Transform
|
3
|
+
class ToSymbol
|
4
|
+
MATCHER = /\A:"?(\w+)"?\Z/.freeze
|
5
|
+
|
6
|
+
def transform?(value, options=nil)
|
7
|
+
options ||= SafeYAML::OPTIONS
|
8
|
+
return false unless options[:deserialize_symbols] && MATCHER.match(value)
|
9
|
+
return true, $1.to_sym
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module SafeYAML
|
2
|
+
class Transform
|
3
|
+
module TransformationMap
|
4
|
+
def self.included(base)
|
5
|
+
base.extend(ClassMethods)
|
6
|
+
end
|
7
|
+
|
8
|
+
class CaseAgnosticMap < Hash
|
9
|
+
def initialize(*args)
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
def include?(key)
|
14
|
+
super(key.downcase)
|
15
|
+
end
|
16
|
+
|
17
|
+
def [](key)
|
18
|
+
super(key.downcase)
|
19
|
+
end
|
20
|
+
|
21
|
+
# OK, I actually don't think it's all that important that this map be
|
22
|
+
# frozen.
|
23
|
+
def freeze
|
24
|
+
self
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module ClassMethods
|
29
|
+
def set_predefined_values(predefined_values)
|
30
|
+
if SafeYAML::YAML_ENGINE == "syck"
|
31
|
+
expanded_map = predefined_values.inject({}) do |hash, (key, value)|
|
32
|
+
hash[key] = value
|
33
|
+
hash[key.capitalize] = value
|
34
|
+
hash[key.upcase] = value
|
35
|
+
hash
|
36
|
+
end
|
37
|
+
else
|
38
|
+
expanded_map = CaseAgnosticMap.new
|
39
|
+
expanded_map.merge!(predefined_values)
|
40
|
+
end
|
41
|
+
|
42
|
+
self.const_set(:PREDEFINED_VALUES, expanded_map.freeze)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
|
4
|
+
|
5
|
+
rvm use 1.8.7@safe_yaml
|
6
|
+
rake spec
|
7
|
+
|
8
|
+
rvm use 1.9.2@safe_yaml
|
9
|
+
YAMLER=syck rake spec
|
10
|
+
|
11
|
+
rvm use 1.9.3@safe_yaml
|
12
|
+
YAMLER=syck rake spec
|
13
|
+
|
14
|
+
rvm use 1.9.2@safe_yaml
|
15
|
+
YAMLER=psych rake spec
|
16
|
+
|
17
|
+
rvm use 1.9.3@safe_yaml
|
18
|
+
YAMLER=psych rake spec
|
19
|
+
|
20
|
+
rvm use 2.0.0@safe_yaml
|
21
|
+
YAMLER=psych rake spec
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.join(File.dirname(__FILE__), "lib", "safe_yaml", "version")
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "safe_yaml"
|
6
|
+
gem.version = SafeYAML::VERSION
|
7
|
+
gem.authors = "Dan Tao"
|
8
|
+
gem.email = "daniel.tao@gmail.com"
|
9
|
+
gem.description = %q{Parse YAML safely, without that pesky arbitrary object deserialization vulnerability}
|
10
|
+
gem.summary = %q{SameYAML provides an alternative implementation of YAML.load suitable for accepting user input in Ruby applications.}
|
11
|
+
gem.homepage = "http://dtao.github.com/safe_yaml/"
|
12
|
+
gem.license = "MIT"
|
13
|
+
gem.files = `git ls-files`.split($\)
|
14
|
+
gem.test_files = gem.files.grep(%r{^spec/})
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
|
17
|
+
gem.required_ruby_version = ">= 1.8.7"
|
18
|
+
end
|
@@ -0,0 +1,250 @@
|
|
1
|
+
module ResolverSpecs
|
2
|
+
def self.included(base)
|
3
|
+
base.module_eval do
|
4
|
+
let(:resolver) { nil }
|
5
|
+
let(:result) { @result }
|
6
|
+
|
7
|
+
def parse(yaml)
|
8
|
+
tree = YAML.parse(yaml.unindent)
|
9
|
+
@result = resolver.resolve_node(tree)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Isn't this how I should've been doing it all along?
|
13
|
+
def parse_and_test(yaml)
|
14
|
+
parse(yaml)
|
15
|
+
@result.should == YAML.unsafe_load(yaml)
|
16
|
+
end
|
17
|
+
|
18
|
+
context "by default" do
|
19
|
+
it "translates maps to hashes" do
|
20
|
+
parse <<-YAML
|
21
|
+
potayto: potahto
|
22
|
+
tomayto: tomahto
|
23
|
+
YAML
|
24
|
+
|
25
|
+
result.should == {
|
26
|
+
"potayto" => "potahto",
|
27
|
+
"tomayto" => "tomahto"
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
it "translates sequences to arrays" do
|
32
|
+
parse <<-YAML
|
33
|
+
- foo
|
34
|
+
- bar
|
35
|
+
- baz
|
36
|
+
YAML
|
37
|
+
|
38
|
+
result.should == ["foo", "bar", "baz"]
|
39
|
+
end
|
40
|
+
|
41
|
+
it "translates most values to strings" do
|
42
|
+
parse "string: value"
|
43
|
+
result.should == { "string" => "value" }
|
44
|
+
end
|
45
|
+
|
46
|
+
it "does not deserialize symbols" do
|
47
|
+
parse ":symbol: value"
|
48
|
+
result.should == { ":symbol" => "value" }
|
49
|
+
end
|
50
|
+
|
51
|
+
it "translates valid integral numbers to integers" do
|
52
|
+
parse "integer: 1"
|
53
|
+
result.should == { "integer" => 1 }
|
54
|
+
end
|
55
|
+
|
56
|
+
it "translates valid decimal numbers to floats" do
|
57
|
+
parse "float: 3.14"
|
58
|
+
result.should == { "float" => 3.14 }
|
59
|
+
end
|
60
|
+
|
61
|
+
it "translates valid dates" do
|
62
|
+
parse "date: 2013-01-24"
|
63
|
+
result.should == { "date" => Date.parse("2013-01-24") }
|
64
|
+
end
|
65
|
+
|
66
|
+
it "translates valid true/false values to booleans" do
|
67
|
+
parse <<-YAML
|
68
|
+
- yes
|
69
|
+
- true
|
70
|
+
- no
|
71
|
+
- false
|
72
|
+
YAML
|
73
|
+
|
74
|
+
result.should == [true, true, false, false]
|
75
|
+
end
|
76
|
+
|
77
|
+
it "translates valid nulls to nil" do
|
78
|
+
parse <<-YAML
|
79
|
+
-
|
80
|
+
- ~
|
81
|
+
- null
|
82
|
+
YAML
|
83
|
+
|
84
|
+
result.should == [nil] * 3
|
85
|
+
end
|
86
|
+
|
87
|
+
it "matches the behavior of the underlying YAML engine w/ respect to capitalization of boolean values" do
|
88
|
+
parse_and_test <<-YAML
|
89
|
+
- true
|
90
|
+
- True
|
91
|
+
- TRUE
|
92
|
+
- tRue
|
93
|
+
- TRue
|
94
|
+
- False
|
95
|
+
- FALSE
|
96
|
+
- fAlse
|
97
|
+
- FALse
|
98
|
+
YAML
|
99
|
+
|
100
|
+
# using Syck: [true, true, true, "tRue", "TRue", false, false, "fAlse", "FALse"]
|
101
|
+
# using Psych: all booleans
|
102
|
+
end
|
103
|
+
|
104
|
+
it "matches the behavior of the underlying YAML engine w/ respect to capitalization of nil values" do
|
105
|
+
parse_and_test <<-YAML
|
106
|
+
- Null
|
107
|
+
- NULL
|
108
|
+
- nUll
|
109
|
+
- NUll
|
110
|
+
YAML
|
111
|
+
|
112
|
+
# using Syck: [nil, nil, "nUll", "NUll"]
|
113
|
+
# using Psych: all nils
|
114
|
+
end
|
115
|
+
|
116
|
+
it "translates quoted empty strings to strings (not nil)" do
|
117
|
+
parse "foo: ''"
|
118
|
+
result.should == { "foo" => "" }
|
119
|
+
end
|
120
|
+
|
121
|
+
it "correctly reverse-translates strings encoded via #to_yaml" do
|
122
|
+
parse "5.10".to_yaml
|
123
|
+
result.should == "5.10"
|
124
|
+
end
|
125
|
+
|
126
|
+
it "does not specially parse any double-quoted strings" do
|
127
|
+
parse <<-YAML
|
128
|
+
- "1"
|
129
|
+
- "3.14"
|
130
|
+
- "true"
|
131
|
+
- "false"
|
132
|
+
- "2013-02-03"
|
133
|
+
- "2013-02-03 16:27:00 -0600"
|
134
|
+
YAML
|
135
|
+
|
136
|
+
result.should == ["1", "3.14", "true", "false", "2013-02-03", "2013-02-03 16:27:00 -0600"]
|
137
|
+
end
|
138
|
+
|
139
|
+
it "does not specially parse any single-quoted strings" do
|
140
|
+
parse <<-YAML
|
141
|
+
- '1'
|
142
|
+
- '3.14'
|
143
|
+
- 'true'
|
144
|
+
- 'false'
|
145
|
+
- '2013-02-03'
|
146
|
+
- '2013-02-03 16:27:00 -0600'
|
147
|
+
YAML
|
148
|
+
|
149
|
+
result.should == ["1", "3.14", "true", "false", "2013-02-03", "2013-02-03 16:27:00 -0600"]
|
150
|
+
end
|
151
|
+
|
152
|
+
it "deals just fine with nested maps" do
|
153
|
+
parse <<-YAML
|
154
|
+
foo:
|
155
|
+
bar:
|
156
|
+
marco: polo
|
157
|
+
YAML
|
158
|
+
|
159
|
+
result.should == { "foo" => { "bar" => { "marco" => "polo" } } }
|
160
|
+
end
|
161
|
+
|
162
|
+
it "deals just fine with nested sequences" do
|
163
|
+
parse <<-YAML
|
164
|
+
- foo
|
165
|
+
-
|
166
|
+
- bar1
|
167
|
+
- bar2
|
168
|
+
-
|
169
|
+
- baz1
|
170
|
+
- baz2
|
171
|
+
YAML
|
172
|
+
|
173
|
+
result.should == ["foo", ["bar1", "bar2", ["baz1", "baz2"]]]
|
174
|
+
end
|
175
|
+
|
176
|
+
it "applies the same transformations to keys as to values" do
|
177
|
+
parse <<-YAML
|
178
|
+
foo: string
|
179
|
+
:bar: symbol
|
180
|
+
1: integer
|
181
|
+
3.14: float
|
182
|
+
2013-01-24: date
|
183
|
+
YAML
|
184
|
+
|
185
|
+
result.should == {
|
186
|
+
"foo" => "string",
|
187
|
+
":bar" => "symbol",
|
188
|
+
1 => "integer",
|
189
|
+
3.14 => "float",
|
190
|
+
Date.parse("2013-01-24") => "date",
|
191
|
+
}
|
192
|
+
end
|
193
|
+
|
194
|
+
it "applies the same transformations to elements in sequences as to all values" do
|
195
|
+
parse <<-YAML
|
196
|
+
- foo
|
197
|
+
- :bar
|
198
|
+
- 1
|
199
|
+
- 3.14
|
200
|
+
- 2013-01-24
|
201
|
+
YAML
|
202
|
+
|
203
|
+
result.should == ["foo", ":bar", 1, 3.14, Date.parse("2013-01-24")]
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
context "for Ruby version #{RUBY_VERSION}" do
|
208
|
+
it "translates valid time values" do
|
209
|
+
parse "time: 2013-01-29 05:58:00 -0800"
|
210
|
+
result.should == { "time" => Time.utc(2013, 1, 29, 13, 58, 0) }
|
211
|
+
end
|
212
|
+
|
213
|
+
it "applies the same transformation to elements in sequences" do
|
214
|
+
parse "- 2013-01-29 05:58:00 -0800"
|
215
|
+
result.should == [Time.utc(2013, 1, 29, 13, 58, 0)]
|
216
|
+
end
|
217
|
+
|
218
|
+
it "applies the same transformation to keys" do
|
219
|
+
parse "2013-01-29 05:58:00 -0800: time"
|
220
|
+
result.should == { Time.utc(2013, 1, 29, 13, 58, 0) => "time" }
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
context "with symbol deserialization enabled" do
|
225
|
+
before :each do
|
226
|
+
SafeYAML::OPTIONS[:deserialize_symbols] = true
|
227
|
+
end
|
228
|
+
|
229
|
+
after :each do
|
230
|
+
SafeYAML.restore_defaults!
|
231
|
+
end
|
232
|
+
|
233
|
+
it "translates values starting with ':' to symbols" do
|
234
|
+
parse "symbol: :value"
|
235
|
+
result.should == { "symbol" => :value }
|
236
|
+
end
|
237
|
+
|
238
|
+
it "applies the same transformation to keys" do
|
239
|
+
parse ":bar: symbol"
|
240
|
+
result.should == { :bar => "symbol" }
|
241
|
+
end
|
242
|
+
|
243
|
+
it "applies the same transformation to elements in sequences" do
|
244
|
+
parse "- :bar"
|
245
|
+
result.should == [:bar]
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|