psych 2.0.14-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. checksums.yaml +7 -0
  2. data/.autotest +18 -0
  3. data/.gemtest +0 -0
  4. data/.travis.yml +16 -0
  5. data/CHANGELOG.rdoc +576 -0
  6. data/Manifest.txt +114 -0
  7. data/README.rdoc +71 -0
  8. data/Rakefile +123 -0
  9. data/ext/psych/depend +3 -0
  10. data/ext/psych/extconf.rb +38 -0
  11. data/ext/psych/psych.c +34 -0
  12. data/ext/psych/psych.h +20 -0
  13. data/ext/psych/psych_emitter.c +555 -0
  14. data/ext/psych/psych_emitter.h +8 -0
  15. data/ext/psych/psych_parser.c +597 -0
  16. data/ext/psych/psych_parser.h +6 -0
  17. data/ext/psych/psych_to_ruby.c +43 -0
  18. data/ext/psych/psych_to_ruby.h +8 -0
  19. data/ext/psych/psych_yaml_tree.c +24 -0
  20. data/ext/psych/psych_yaml_tree.h +8 -0
  21. data/ext/psych/yaml/LICENSE +19 -0
  22. data/ext/psych/yaml/api.c +1415 -0
  23. data/ext/psych/yaml/config.h +10 -0
  24. data/ext/psych/yaml/dumper.c +394 -0
  25. data/ext/psych/yaml/emitter.c +2329 -0
  26. data/ext/psych/yaml/loader.c +459 -0
  27. data/ext/psych/yaml/parser.c +1370 -0
  28. data/ext/psych/yaml/reader.c +469 -0
  29. data/ext/psych/yaml/scanner.c +3576 -0
  30. data/ext/psych/yaml/writer.c +141 -0
  31. data/ext/psych/yaml/yaml.h +1971 -0
  32. data/ext/psych/yaml/yaml_private.h +664 -0
  33. data/lib/psych.jar +0 -0
  34. data/lib/psych.rb +504 -0
  35. data/lib/psych/class_loader.rb +101 -0
  36. data/lib/psych/coder.rb +94 -0
  37. data/lib/psych/core_ext.rb +35 -0
  38. data/lib/psych/deprecated.rb +85 -0
  39. data/lib/psych/exception.rb +13 -0
  40. data/lib/psych/handler.rb +249 -0
  41. data/lib/psych/handlers/document_stream.rb +22 -0
  42. data/lib/psych/handlers/recorder.rb +39 -0
  43. data/lib/psych/json/ruby_events.rb +19 -0
  44. data/lib/psych/json/stream.rb +16 -0
  45. data/lib/psych/json/tree_builder.rb +12 -0
  46. data/lib/psych/json/yaml_events.rb +29 -0
  47. data/lib/psych/nodes.rb +77 -0
  48. data/lib/psych/nodes/alias.rb +18 -0
  49. data/lib/psych/nodes/document.rb +60 -0
  50. data/lib/psych/nodes/mapping.rb +56 -0
  51. data/lib/psych/nodes/node.rb +55 -0
  52. data/lib/psych/nodes/scalar.rb +67 -0
  53. data/lib/psych/nodes/sequence.rb +81 -0
  54. data/lib/psych/nodes/stream.rb +37 -0
  55. data/lib/psych/omap.rb +4 -0
  56. data/lib/psych/parser.rb +51 -0
  57. data/lib/psych/scalar_scanner.rb +149 -0
  58. data/lib/psych/set.rb +4 -0
  59. data/lib/psych/stream.rb +37 -0
  60. data/lib/psych/streaming.rb +27 -0
  61. data/lib/psych/syntax_error.rb +21 -0
  62. data/lib/psych/tree_builder.rb +96 -0
  63. data/lib/psych/versions.rb +3 -0
  64. data/lib/psych/visitors.rb +6 -0
  65. data/lib/psych/visitors/depth_first.rb +26 -0
  66. data/lib/psych/visitors/emitter.rb +51 -0
  67. data/lib/psych/visitors/json_tree.rb +24 -0
  68. data/lib/psych/visitors/to_ruby.rb +404 -0
  69. data/lib/psych/visitors/visitor.rb +19 -0
  70. data/lib/psych/visitors/yaml_tree.rb +605 -0
  71. data/lib/psych/y.rb +9 -0
  72. data/lib/psych_jars.rb +5 -0
  73. data/test/psych/handlers/test_recorder.rb +25 -0
  74. data/test/psych/helper.rb +121 -0
  75. data/test/psych/json/test_stream.rb +109 -0
  76. data/test/psych/nodes/test_enumerable.rb +43 -0
  77. data/test/psych/test_alias_and_anchor.rb +96 -0
  78. data/test/psych/test_array.rb +57 -0
  79. data/test/psych/test_boolean.rb +36 -0
  80. data/test/psych/test_class.rb +36 -0
  81. data/test/psych/test_coder.rb +206 -0
  82. data/test/psych/test_date_time.rb +38 -0
  83. data/test/psych/test_deprecated.rb +214 -0
  84. data/test/psych/test_document.rb +46 -0
  85. data/test/psych/test_emitter.rb +93 -0
  86. data/test/psych/test_encoding.rb +259 -0
  87. data/test/psych/test_exception.rb +157 -0
  88. data/test/psych/test_hash.rb +94 -0
  89. data/test/psych/test_json_tree.rb +65 -0
  90. data/test/psych/test_merge_keys.rb +180 -0
  91. data/test/psych/test_nil.rb +18 -0
  92. data/test/psych/test_null.rb +19 -0
  93. data/test/psych/test_numeric.rb +45 -0
  94. data/test/psych/test_object.rb +44 -0
  95. data/test/psych/test_object_references.rb +71 -0
  96. data/test/psych/test_omap.rb +75 -0
  97. data/test/psych/test_parser.rb +339 -0
  98. data/test/psych/test_psych.rb +168 -0
  99. data/test/psych/test_safe_load.rb +97 -0
  100. data/test/psych/test_scalar.rb +11 -0
  101. data/test/psych/test_scalar_scanner.rb +106 -0
  102. data/test/psych/test_serialize_subclasses.rb +38 -0
  103. data/test/psych/test_set.rb +49 -0
  104. data/test/psych/test_stream.rb +93 -0
  105. data/test/psych/test_string.rb +226 -0
  106. data/test/psych/test_struct.rb +49 -0
  107. data/test/psych/test_symbol.rb +25 -0
  108. data/test/psych/test_tainted.rb +130 -0
  109. data/test/psych/test_to_yaml_properties.rb +63 -0
  110. data/test/psych/test_tree_builder.rb +79 -0
  111. data/test/psych/test_yaml.rb +1292 -0
  112. data/test/psych/test_yamldbm.rb +193 -0
  113. data/test/psych/test_yamlstore.rb +85 -0
  114. data/test/psych/visitors/test_depth_first.rb +49 -0
  115. data/test/psych/visitors/test_emitter.rb +144 -0
  116. data/test/psych/visitors/test_to_ruby.rb +333 -0
  117. data/test/psych/visitors/test_yaml_tree.rb +173 -0
  118. metadata +240 -0
@@ -0,0 +1,93 @@
1
+ require_relative 'helper'
2
+
3
+ module Psych
4
+ class TestStream < TestCase
5
+ def test_parse_partial
6
+ rb = Psych.parse("--- foo\n...\n--- `").to_ruby
7
+ assert_equal 'foo', rb
8
+ end
9
+
10
+ def test_load_partial
11
+ rb = Psych.load("--- foo\n...\n--- `")
12
+ assert_equal 'foo', rb
13
+ end
14
+
15
+ def test_parse_stream_yields_documents
16
+ list = []
17
+ Psych.parse_stream("--- foo\n...\n--- bar") do |doc|
18
+ list << doc.to_ruby
19
+ end
20
+ assert_equal %w{ foo bar }, list
21
+ end
22
+
23
+ def test_parse_stream_break
24
+ list = []
25
+ Psych.parse_stream("--- foo\n...\n--- `") do |doc|
26
+ list << doc.to_ruby
27
+ break
28
+ end
29
+ assert_equal %w{ foo }, list
30
+ end
31
+
32
+ def test_load_stream_yields_documents
33
+ list = []
34
+ Psych.load_stream("--- foo\n...\n--- bar") do |ruby|
35
+ list << ruby
36
+ end
37
+ assert_equal %w{ foo bar }, list
38
+ end
39
+
40
+ def test_load_stream_break
41
+ list = []
42
+ Psych.load_stream("--- foo\n...\n--- `") do |ruby|
43
+ list << ruby
44
+ break
45
+ end
46
+ assert_equal %w{ foo }, list
47
+ end
48
+
49
+ def test_explicit_documents
50
+ io = StringIO.new
51
+ stream = Psych::Stream.new(io)
52
+ stream.start
53
+ stream.push({ 'foo' => 'bar' })
54
+
55
+ assert !stream.finished?, 'stream not finished'
56
+ stream.finish
57
+ assert stream.finished?, 'stream finished'
58
+
59
+ assert_match(/^---/, io.string)
60
+ assert_match(/\.\.\.$/, io.string)
61
+ end
62
+
63
+ def test_start_takes_block
64
+ io = StringIO.new
65
+ stream = Psych::Stream.new(io)
66
+ stream.start do |emitter|
67
+ emitter.push({ 'foo' => 'bar' })
68
+ end
69
+
70
+ assert stream.finished?, 'stream finished'
71
+ assert_match(/^---/, io.string)
72
+ assert_match(/\.\.\.$/, io.string)
73
+ end
74
+
75
+ def test_no_backreferences
76
+ io = StringIO.new
77
+ stream = Psych::Stream.new(io)
78
+ stream.start do |emitter|
79
+ x = { 'foo' => 'bar' }
80
+ emitter.push x
81
+ emitter.push x
82
+ end
83
+
84
+ assert stream.finished?, 'stream finished'
85
+ assert_match(/^---/, io.string)
86
+ assert_match(/\.\.\.$/, io.string)
87
+ assert_equal 2, io.string.scan('---').length
88
+ assert_equal 2, io.string.scan('...').length
89
+ assert_equal 2, io.string.scan('foo').length
90
+ assert_equal 2, io.string.scan('bar').length
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,226 @@
1
+ # encoding: UTF-8
2
+ require_relative 'helper'
3
+
4
+ module Psych
5
+ class TestString < TestCase
6
+ class X < String
7
+ end
8
+
9
+ class Y < String
10
+ attr_accessor :val
11
+ end
12
+
13
+ class Z < String
14
+ def initialize
15
+ force_encoding Encoding::US_ASCII
16
+ end
17
+ end
18
+
19
+ def test_string_with_newline
20
+ assert_equal "1\n2", Psych.load("--- ! '1\n\n 2'\n")
21
+ end
22
+
23
+ def test_no_doublequotes_with_special_characters
24
+ assert_equal 2, Psych.dump(%Q{<%= ENV["PATH"] %>}).count('"')
25
+ end
26
+
27
+ def test_no_quotes_when_start_with_non_ascii_character
28
+ yaml = Psych.dump 'Český non-ASCII'.encode(Encoding::UTF_8)
29
+ assert_match(/---\s*[^"'!]+$/, yaml)
30
+ end
31
+
32
+ def test_doublequotes_when_there_is_a_single
33
+ str = "@123'abc"
34
+ yaml = Psych.dump str
35
+ assert_match /---\s*"/, yaml
36
+ assert_equal str, Psych.load(yaml)
37
+ end
38
+
39
+ def test_plain_when_shorten_than_line_width_and_no_final_line_break
40
+ str = "Lorem ipsum"
41
+ yaml = Psych.dump str, line_width: 12
42
+ assert_match /---\s*[^>|]+\n/, yaml
43
+ assert_equal str, Psych.load(yaml)
44
+ end
45
+
46
+ def test_plain_when_shorten_than_line_width_and_with_final_line_break
47
+ str = "Lorem ipsum\n"
48
+ yaml = Psych.dump str, line_width: 12
49
+ assert_match /---\s*[^>|]+\n/, yaml
50
+ assert_equal str, Psych.load(yaml)
51
+ end
52
+
53
+ def test_folded_when_longer_than_line_width_and_with_final_line_break
54
+ str = "Lorem ipsum dolor sit\n"
55
+ yaml = Psych.dump str, line_width: 12
56
+ assert_match /---\s*>\n(.*\n){2}\Z/, yaml
57
+ assert_equal str, Psych.load(yaml)
58
+ end
59
+
60
+ # http://yaml.org/spec/1.2/2009-07-21/spec.html#id2593651
61
+ def test_folded_strip_when_longer_than_line_width_and_no_newlines
62
+ str = "Lorem ipsum dolor sit amet, consectetur"
63
+ yaml = Psych.dump str, line_width: 12
64
+ assert_match /---\s*>-\n(.*\n){3}\Z/, yaml
65
+ assert_equal str, Psych.load(yaml)
66
+ end
67
+
68
+ def test_literal_when_inner_and_final_line_break
69
+ [
70
+ "Lorem ipsum\ndolor\n",
71
+ "Lorem ipsum\nZolor\n",
72
+ ].each do |str|
73
+ yaml = Psych.dump str, line_width: 12
74
+ assert_match /---\s*\|\n(.*\n){2}\Z/, yaml
75
+ assert_equal str, Psych.load(yaml)
76
+ end
77
+ end
78
+
79
+ # http://yaml.org/spec/1.2/2009-07-21/spec.html#id2593651
80
+ def test_literal_strip_when_inner_line_break_and_no_final_line_break
81
+ [
82
+ "Lorem ipsum\ndolor",
83
+ "Lorem ipsum\nZolor",
84
+ ].each do |str|
85
+ yaml = Psych.dump str, line_width: 12
86
+ assert_match /---\s*\|-\n(.*\n){2}\Z/, yaml
87
+ assert_equal str, Psych.load(yaml)
88
+ end
89
+ end
90
+
91
+ def test_cycle_x
92
+ str = X.new 'abc'
93
+ assert_cycle str
94
+ end
95
+
96
+ def test_dash_dot
97
+ assert_cycle '-.'
98
+ assert_cycle '+.'
99
+ end
100
+
101
+ def test_string_subclass_with_anchor
102
+ y = Psych.load <<-eoyml
103
+ ---
104
+ body:
105
+ string: &70121654388580 !ruby/string
106
+ str: ! 'foo'
107
+ x:
108
+ body: *70121654388580
109
+ eoyml
110
+ assert_equal({"body"=>{"string"=>"foo", "x"=>{"body"=>"foo"}}}, y)
111
+ end
112
+
113
+ def test_self_referential_string
114
+ y = Psych.load <<-eoyml
115
+ ---
116
+ string: &70121654388580 !ruby/string
117
+ str: ! 'foo'
118
+ body: *70121654388580
119
+ eoyml
120
+
121
+ assert_equal({"string"=>"foo"}, y)
122
+ value = y['string']
123
+ assert_equal value, value.instance_variable_get(:@body)
124
+ end
125
+
126
+ def test_another_subclass_with_attributes
127
+ y = Psych.load Psych.dump Y.new("foo").tap {|y| y.val = 1}
128
+ assert_equal "foo", y
129
+ assert_equal Y, y.class
130
+ assert_equal 1, y.val
131
+ end
132
+
133
+ def test_backwards_with_syck
134
+ x = Psych.load "--- !str:#{X.name} foo\n\n"
135
+ assert_equal X, x.class
136
+ assert_equal 'foo', x
137
+ end
138
+
139
+ def test_empty_subclass
140
+ assert_match "!ruby/string:#{X}", Psych.dump(X.new)
141
+ x = Psych.load Psych.dump X.new
142
+ assert_equal X, x.class
143
+ end
144
+
145
+ def test_empty_character_subclass
146
+ assert_match "!ruby/string:#{Z}", Psych.dump(Z.new)
147
+ x = Psych.load Psych.dump Z.new
148
+ assert_equal Z, x.class
149
+ end
150
+
151
+ def test_subclass_with_attributes
152
+ y = Psych.load Psych.dump Y.new.tap {|y| y.val = 1}
153
+ assert_equal Y, y.class
154
+ assert_equal 1, y.val
155
+ end
156
+
157
+ def test_string_with_base_60
158
+ yaml = Psych.dump '01:03:05'
159
+ assert_match "'01:03:05'", yaml
160
+ assert_equal '01:03:05', Psych.load(yaml)
161
+ end
162
+
163
+ def test_nonascii_string_as_binary
164
+ string = "hello \x80 world!"
165
+ string.force_encoding 'ascii-8bit'
166
+ yml = Psych.dump string
167
+ assert_match(/binary/, yml)
168
+ assert_equal string, Psych.load(yml)
169
+ end
170
+
171
+ def test_binary_string_null
172
+ string = "\x00"
173
+ yml = Psych.dump string
174
+ assert_match(/binary/, yml)
175
+ assert_equal string, Psych.load(yml)
176
+ end
177
+
178
+ def test_binary_string
179
+ string = binary_string
180
+ yml = Psych.dump string
181
+ assert_match(/binary/, yml)
182
+ assert_equal string, Psych.load(yml)
183
+ end
184
+
185
+ def test_non_binary_string
186
+ string = binary_string(0.29)
187
+ yml = Psych.dump string
188
+ refute_match(/binary/, yml)
189
+ assert_equal string, Psych.load(yml)
190
+ end
191
+
192
+ def test_ascii_only_8bit_string
193
+ string = "abc".encode(Encoding::ASCII_8BIT)
194
+ yml = Psych.dump string
195
+ refute_match(/binary/, yml)
196
+ assert_equal string, Psych.load(yml)
197
+ end
198
+
199
+ def test_string_with_ivars
200
+ food = "is delicious"
201
+ ivar = "on rock and roll"
202
+ food.instance_variable_set(:@we_built_this_city, ivar)
203
+
204
+ Psych.load Psych.dump food
205
+ assert_equal ivar, food.instance_variable_get(:@we_built_this_city)
206
+ end
207
+
208
+ def test_binary
209
+ string = [0, 123,22, 44, 9, 32, 34, 39].pack('C*')
210
+ assert_cycle string
211
+ end
212
+
213
+ def test_float_confusion
214
+ assert_cycle '1.'
215
+ end
216
+
217
+ def binary_string percentage = 0.31, length = 100
218
+ string = ''
219
+ (percentage * length).to_i.times do |i|
220
+ string << "\b"
221
+ end
222
+ string << 'a' * (length - string.length)
223
+ string
224
+ end
225
+ end
226
+ end
@@ -0,0 +1,49 @@
1
+ require_relative 'helper'
2
+
3
+ class PsychStructWithIvar < Struct.new(:foo)
4
+ attr_reader :bar
5
+ def initialize *args
6
+ super
7
+ @bar = 'hello'
8
+ end
9
+ end
10
+
11
+ module Psych
12
+ class TestStruct < TestCase
13
+ class StructSubclass < Struct.new(:foo)
14
+ def initialize foo, bar
15
+ super(foo)
16
+ @bar = bar
17
+ end
18
+ end
19
+
20
+ def test_self_referential_struct
21
+ ss = StructSubclass.new(nil, 'foo')
22
+ ss.foo = ss
23
+
24
+ loaded = Psych.load(Psych.dump(ss))
25
+ assert_instance_of(StructSubclass, loaded.foo)
26
+
27
+ assert_equal(ss, loaded)
28
+ end
29
+
30
+ def test_roundtrip
31
+ thing = PsychStructWithIvar.new('bar')
32
+ struct = Psych.load(Psych.dump(thing))
33
+
34
+ assert_equal 'hello', struct.bar
35
+ assert_equal 'bar', struct.foo
36
+ end
37
+
38
+ def test_load
39
+ obj = Psych.load(<<-eoyml)
40
+ --- !ruby/struct:PsychStructWithIvar
41
+ :foo: bar
42
+ :@bar: hello
43
+ eoyml
44
+
45
+ assert_equal 'hello', obj.bar
46
+ assert_equal 'bar', obj.foo
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,25 @@
1
+ require_relative 'helper'
2
+
3
+ module Psych
4
+ class TestSymbol < TestCase
5
+ def test_cycle_empty
6
+ assert_cycle :''
7
+ end
8
+
9
+ def test_cycle_colon
10
+ assert_cycle :':'
11
+ end
12
+
13
+ def test_cycle
14
+ assert_cycle :a
15
+ end
16
+
17
+ def test_stringy
18
+ assert_cycle :"1"
19
+ end
20
+
21
+ def test_load_quoted
22
+ assert_equal :"1", Psych.load("--- :'1'\n")
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,130 @@
1
+ require_relative 'helper'
2
+
3
+ module Psych
4
+ class TestStringTainted < TestCase
5
+ class Tainted < Handler
6
+ attr_reader :tc
7
+
8
+ def initialize tc
9
+ @tc = tc
10
+ end
11
+
12
+ def start_document version, tags, implicit
13
+ tags.flatten.each do |tag|
14
+ assert_taintedness tag
15
+ end
16
+ end
17
+
18
+ def alias name
19
+ assert_taintedness name
20
+ end
21
+
22
+ def scalar value, anchor, tag, plain, quoted, style
23
+ assert_taintedness value
24
+ assert_taintedness tag if tag
25
+ assert_taintedness anchor if anchor
26
+ end
27
+
28
+ def start_sequence anchor, tag, implicit, style
29
+ assert_taintedness tag if tag
30
+ assert_taintedness anchor if anchor
31
+ end
32
+
33
+ def start_mapping anchor, tag, implicit, style
34
+ assert_taintedness tag if tag
35
+ assert_taintedness anchor if anchor
36
+ end
37
+
38
+ def assert_taintedness thing, message = "'#{thing}' should be tainted"
39
+ tc.assert thing.tainted?, message
40
+ end
41
+ end
42
+
43
+ class Untainted < Tainted
44
+ def assert_taintedness thing, message = "'#{thing}' should not be tainted"
45
+ tc.assert !thing.tainted?, message
46
+ end
47
+ end
48
+
49
+
50
+ def setup
51
+ handler = Tainted.new self
52
+ @parser = Psych::Parser.new handler
53
+ end
54
+
55
+ def test_tags_are_tainted
56
+ assert_taintedness "%TAG !yaml! tag:yaml.org,2002:\n---\n!yaml!str \"foo\""
57
+ end
58
+
59
+ def test_alias
60
+ assert_taintedness "--- &ponies\n- foo\n- *ponies"
61
+ end
62
+
63
+ def test_scalar
64
+ assert_taintedness "--- ponies"
65
+ end
66
+
67
+ def test_anchor
68
+ assert_taintedness "--- &hi ponies"
69
+ end
70
+
71
+ def test_scalar_tag
72
+ assert_taintedness "--- !str ponies"
73
+ end
74
+
75
+ def test_seq_start_tag
76
+ assert_taintedness "--- !!seq [ a ]"
77
+ end
78
+
79
+ def test_seq_start_anchor
80
+ assert_taintedness "--- &zomg [ a ]"
81
+ end
82
+
83
+ def test_seq_mapping_tag
84
+ assert_taintedness "--- !!map { a: b }"
85
+ end
86
+
87
+ def test_seq_mapping_anchor
88
+ assert_taintedness "--- &himom { a: b }"
89
+ end
90
+
91
+ def assert_taintedness string
92
+ @parser.parse string.taint
93
+ end
94
+ end
95
+
96
+ class TestStringUntainted < TestStringTainted
97
+ def setup
98
+ handler = Untainted.new self
99
+ @parser = Psych::Parser.new handler
100
+ end
101
+
102
+ def assert_taintedness string
103
+ @parser.parse string
104
+ end
105
+ end
106
+
107
+ class TestStringIOUntainted < TestStringTainted
108
+ def setup
109
+ handler = Untainted.new self
110
+ @parser = Psych::Parser.new handler
111
+ end
112
+
113
+ def assert_taintedness string
114
+ @parser.parse StringIO.new(string)
115
+ end
116
+ end
117
+
118
+ class TestIOTainted < TestStringTainted
119
+ def assert_taintedness string
120
+ Tempfile.create(['something', 'yml']) {|t|
121
+ t.binmode
122
+ t.write string
123
+ t.close
124
+ File.open(t.path, 'r:bom|utf-8') { |f|
125
+ @parser.parse f
126
+ }
127
+ }
128
+ end
129
+ end
130
+ end