psych 2.0.9 → 2.0.10
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.
- checksums.yaml +4 -4
- data/lib/psych.rb +1 -1
- data/lib/psych/visitors/yaml_tree.rb +64 -54
- data/test/psych/test_hash.rb +0 -6
- data/test/psych/test_string.rb +48 -2
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0e5c90da9dd1e414da2fd88c99a8a54ddec4c086
|
|
4
|
+
data.tar.gz: ffcc4e20b755b2e0beb3747d3606daa8f4cb6819
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dfe83058664c3da10a4a42a64967beca000f69ae3fde2857faa997464bfd518221ec864d196b88777f8d20293f6bd8bf814f236bb237f99369562bcd334065e9
|
|
7
|
+
data.tar.gz: 81d19e5195c344ef08dca2aab53d9d13b46327fb937756b6c09211856ab14c1a948a197676b3651fa40a3df3d783292e2488d6632ca959fbd49069f2bf37c366
|
data/lib/psych.rb
CHANGED
|
@@ -62,13 +62,14 @@ module Psych
|
|
|
62
62
|
|
|
63
63
|
def initialize emitter, ss, options
|
|
64
64
|
super()
|
|
65
|
-
@started
|
|
66
|
-
@finished
|
|
67
|
-
@emitter
|
|
68
|
-
@st
|
|
69
|
-
@ss
|
|
70
|
-
@options
|
|
71
|
-
@
|
|
65
|
+
@started = false
|
|
66
|
+
@finished = false
|
|
67
|
+
@emitter = emitter
|
|
68
|
+
@st = Registrar.new
|
|
69
|
+
@ss = ss
|
|
70
|
+
@options = options
|
|
71
|
+
@line_width = options[:line_width]
|
|
72
|
+
@coders = []
|
|
72
73
|
|
|
73
74
|
@dispatch_cache = Hash.new do |h,klass|
|
|
74
75
|
method = "visit_#{(klass.name || '').split('::').join('_')}"
|
|
@@ -301,46 +302,46 @@ module Psych
|
|
|
301
302
|
quote = true
|
|
302
303
|
style = Nodes::Scalar::PLAIN
|
|
303
304
|
tag = nil
|
|
304
|
-
str = o
|
|
305
305
|
|
|
306
306
|
if binary?(o)
|
|
307
|
-
|
|
307
|
+
o = [o].pack('m').chomp
|
|
308
308
|
tag = '!binary' # FIXME: change to below when syck is removed
|
|
309
309
|
#tag = 'tag:yaml.org,2002:binary'
|
|
310
310
|
style = Nodes::Scalar::LITERAL
|
|
311
311
|
plain = false
|
|
312
312
|
quote = false
|
|
313
|
-
elsif o =~ /\n/
|
|
313
|
+
elsif o =~ /\n[^\Z]/ # match \n except blank line at the end of string
|
|
314
314
|
style = Nodes::Scalar::LITERAL
|
|
315
315
|
elsif o == '<<'
|
|
316
316
|
style = Nodes::Scalar::SINGLE_QUOTED
|
|
317
317
|
tag = 'tag:yaml.org,2002:str'
|
|
318
318
|
plain = false
|
|
319
319
|
quote = false
|
|
320
|
+
elsif @line_width && o.length > @line_width
|
|
321
|
+
style = Nodes::Scalar::FOLDED
|
|
320
322
|
elsif o =~ /^[^[:word:]][^"]*$/
|
|
321
323
|
style = Nodes::Scalar::DOUBLE_QUOTED
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
style = Nodes::Scalar::SINGLE_QUOTED
|
|
325
|
-
end
|
|
324
|
+
elsif not String === @ss.tokenize(o)
|
|
325
|
+
style = Nodes::Scalar::SINGLE_QUOTED
|
|
326
326
|
end
|
|
327
327
|
|
|
328
|
-
|
|
328
|
+
is_primitive = o.class == ::String
|
|
329
|
+
ivars = find_ivars o, is_primitive
|
|
329
330
|
|
|
330
331
|
if ivars.empty?
|
|
331
|
-
unless
|
|
332
|
+
unless is_primitive
|
|
332
333
|
tag = "!ruby/string:#{o.class}"
|
|
333
334
|
plain = false
|
|
334
335
|
quote = false
|
|
335
336
|
end
|
|
336
|
-
@emitter.scalar
|
|
337
|
+
@emitter.scalar o, nil, tag, plain, quote, style
|
|
337
338
|
else
|
|
338
339
|
maptag = '!ruby/string'
|
|
339
340
|
maptag << ":#{o.class}" unless o.class == ::String
|
|
340
341
|
|
|
341
342
|
register o, @emitter.start_mapping(nil, maptag, false, Nodes::Mapping::BLOCK)
|
|
342
343
|
@emitter.scalar 'str', nil, nil, true, false, Nodes::Scalar::ANY
|
|
343
|
-
@emitter.scalar
|
|
344
|
+
@emitter.scalar o, nil, tag, plain, quote, style
|
|
344
345
|
|
|
345
346
|
dump_ivars o
|
|
346
347
|
|
|
@@ -367,45 +368,15 @@ module Psych
|
|
|
367
368
|
end
|
|
368
369
|
|
|
369
370
|
def visit_Hash o
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
if ivars.any?
|
|
373
|
-
tag = "!ruby/hash-with-ivars"
|
|
374
|
-
tag << ":#{o.class}" unless o.class == ::Hash
|
|
375
|
-
|
|
376
|
-
register(o, @emitter.start_mapping(nil, tag, false, Psych::Nodes::Mapping::BLOCK))
|
|
377
|
-
|
|
378
|
-
@emitter.scalar 'elements', nil, nil, true, false, Nodes::Scalar::ANY
|
|
379
|
-
|
|
380
|
-
@emitter.start_mapping nil, nil, true, Nodes::Mapping::BLOCK
|
|
371
|
+
if o.class == ::Hash
|
|
372
|
+
register(o, @emitter.start_mapping(nil, nil, true, Psych::Nodes::Mapping::BLOCK))
|
|
381
373
|
o.each do |k,v|
|
|
382
374
|
accept k
|
|
383
375
|
accept v
|
|
384
376
|
end
|
|
385
377
|
@emitter.end_mapping
|
|
386
|
-
|
|
387
|
-
@emitter.scalar 'ivars', nil, nil, true, false, Nodes::Scalar::ANY
|
|
388
|
-
|
|
389
|
-
@emitter.start_mapping nil, nil, true, Nodes::Mapping::BLOCK
|
|
390
|
-
o.instance_variables.each do |ivar|
|
|
391
|
-
accept ivar
|
|
392
|
-
accept o.instance_variable_get ivar
|
|
393
|
-
end
|
|
394
|
-
@emitter.end_mapping
|
|
395
|
-
|
|
396
|
-
@emitter.end_mapping
|
|
397
378
|
else
|
|
398
|
-
|
|
399
|
-
implicit = !tag
|
|
400
|
-
|
|
401
|
-
register(o, @emitter.start_mapping(nil, tag, implicit, Psych::Nodes::Mapping::BLOCK))
|
|
402
|
-
|
|
403
|
-
o.each do |k,v|
|
|
404
|
-
accept k
|
|
405
|
-
accept v
|
|
406
|
-
end
|
|
407
|
-
|
|
408
|
-
@emitter.end_mapping
|
|
379
|
+
visit_hash_subclass o
|
|
409
380
|
end
|
|
410
381
|
end
|
|
411
382
|
|
|
@@ -468,7 +439,8 @@ module Psych
|
|
|
468
439
|
|
|
469
440
|
def visit_array_subclass o
|
|
470
441
|
tag = "!ruby/array:#{o.class}"
|
|
471
|
-
|
|
442
|
+
ivars = o.instance_variables
|
|
443
|
+
if ivars.empty?
|
|
472
444
|
node = @emitter.start_sequence(nil, tag, false, Nodes::Sequence::BLOCK)
|
|
473
445
|
register o, node
|
|
474
446
|
o.each { |c| accept c }
|
|
@@ -486,12 +458,50 @@ module Psych
|
|
|
486
458
|
# Dump the ivars
|
|
487
459
|
accept 'ivars'
|
|
488
460
|
@emitter.start_mapping(nil, nil, true, Nodes::Sequence::BLOCK)
|
|
461
|
+
ivars.each do |ivar|
|
|
462
|
+
accept ivar
|
|
463
|
+
accept o.instance_variable_get ivar
|
|
464
|
+
end
|
|
465
|
+
@emitter.end_mapping
|
|
466
|
+
|
|
467
|
+
@emitter.end_mapping
|
|
468
|
+
end
|
|
469
|
+
end
|
|
470
|
+
|
|
471
|
+
def visit_hash_subclass o
|
|
472
|
+
ivars = o.instance_variables
|
|
473
|
+
if ivars.any?
|
|
474
|
+
tag = "!ruby/hash-with-ivars:#{o.class}"
|
|
475
|
+
node = @emitter.start_mapping(nil, tag, false, Psych::Nodes::Mapping::BLOCK)
|
|
476
|
+
register(o, node)
|
|
477
|
+
|
|
478
|
+
# Dump the elements
|
|
479
|
+
accept 'elements'
|
|
480
|
+
@emitter.start_mapping nil, nil, true, Nodes::Mapping::BLOCK
|
|
481
|
+
o.each do |k,v|
|
|
482
|
+
accept k
|
|
483
|
+
accept v
|
|
484
|
+
end
|
|
485
|
+
@emitter.end_mapping
|
|
486
|
+
|
|
487
|
+
# Dump the ivars
|
|
488
|
+
accept 'ivars'
|
|
489
|
+
@emitter.start_mapping nil, nil, true, Nodes::Mapping::BLOCK
|
|
489
490
|
o.instance_variables.each do |ivar|
|
|
490
491
|
accept ivar
|
|
491
492
|
accept o.instance_variable_get ivar
|
|
492
493
|
end
|
|
493
494
|
@emitter.end_mapping
|
|
494
495
|
|
|
496
|
+
@emitter.end_mapping
|
|
497
|
+
else
|
|
498
|
+
tag = "!ruby/hash:#{o.class}"
|
|
499
|
+
node = @emitter.start_mapping(nil, tag, false, Psych::Nodes::Mapping::BLOCK)
|
|
500
|
+
register(o, node)
|
|
501
|
+
o.each do |k,v|
|
|
502
|
+
accept k
|
|
503
|
+
accept v
|
|
504
|
+
end
|
|
495
505
|
@emitter.end_mapping
|
|
496
506
|
end
|
|
497
507
|
end
|
|
@@ -524,7 +534,7 @@ module Psych
|
|
|
524
534
|
end
|
|
525
535
|
|
|
526
536
|
# FIXME: remove this method once "to_yaml_properties" is removed
|
|
527
|
-
def find_ivars target
|
|
537
|
+
def find_ivars target, is_primitive=false
|
|
528
538
|
begin
|
|
529
539
|
loc = target.method(:to_yaml_properties).source_location.first
|
|
530
540
|
unless loc.start_with?(Psych::DEPRECATED) || loc.end_with?('rubytypes.rb')
|
|
@@ -538,7 +548,7 @@ module Psych
|
|
|
538
548
|
# and it's OK to skip it since it's only to emit a warning.
|
|
539
549
|
end
|
|
540
550
|
|
|
541
|
-
target.instance_variables
|
|
551
|
+
is_primitive ? [] : target.instance_variables
|
|
542
552
|
end
|
|
543
553
|
|
|
544
554
|
def register target, yaml_obj
|
data/test/psych/test_hash.rb
CHANGED
|
@@ -38,12 +38,6 @@ module Psych
|
|
|
38
38
|
assert_cycle t1
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
-
def test_hash_with_ivars
|
|
42
|
-
@hash.instance_variable_set :@foo, 'bar'
|
|
43
|
-
dup = Psych.load Psych.dump @hash
|
|
44
|
-
assert_equal 'bar', dup.instance_variable_get(:@foo)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
41
|
def test_hash_subclass_with_ivars
|
|
48
42
|
x = X.new
|
|
49
43
|
x[:a] = 'b'
|
data/test/psych/test_string.rb
CHANGED
|
@@ -30,8 +30,54 @@ module Psych
|
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def test_doublequotes_when_there_is_a_single
|
|
33
|
-
|
|
34
|
-
|
|
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
|
+
str = "Lorem ipsum\ndolor\n"
|
|
70
|
+
yaml = Psych.dump str, line_width: 12
|
|
71
|
+
assert_match /---\s*|\n(.*\n){2}\Z/, yaml
|
|
72
|
+
assert_equal str, Psych.load(yaml)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# http://yaml.org/spec/1.2/2009-07-21/spec.html#id2593651
|
|
76
|
+
def test_literal_strip_when_inner_line_break_and_no_final_line_break
|
|
77
|
+
str = "Lorem ipsum\ndolor"
|
|
78
|
+
yaml = Psych.dump str, line_width: 12
|
|
79
|
+
assert_match /---\s*|-\n(.*\n){2}\Z/, yaml
|
|
80
|
+
assert_equal str, Psych.load(yaml)
|
|
35
81
|
end
|
|
36
82
|
|
|
37
83
|
def test_cycle_x
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: psych
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Aaron Patterson
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-01-
|
|
11
|
+
date: 2015-01-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rdoc
|