psych 2.0.8 → 2.0.9
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/.travis.yml +3 -2
- data/CHANGELOG.rdoc +16 -0
- data/Rakefile +3 -1
- data/lib/psych.rb +1 -1
- data/lib/psych/visitors/to_ruby.rb +15 -1
- data/lib/psych/visitors/yaml_tree.rb +38 -9
- data/test/psych/test_hash.rb +44 -0
- data/test/psych/test_string.rb +6 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff8cb5130ddeec957e2ea9cb3743aff24dba4dc9
|
4
|
+
data.tar.gz: 71ee9f61849d041bea7f7e7ffb90f380d315eaab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9641a5d5820bee5cb15db5c768e094ec5158b3c7f7d2ec4f1e91933f046cb129b6c316339e8293cac73eb34100ca901a90c029341ca5053d47a1d531753d1efc
|
7
|
+
data.tar.gz: 7e270db26bdd10fef4c1c809f780f23699a2196a16cb3f394d1ee9a7c48f8ef57184fe805c125f30dc89d428eb833c50fbb2935b95dad308cfc990d09b7025d5
|
data/.travis.yml
CHANGED
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
Fri Jan 9 07:13:55 2015 Aaron Patterson <aaron@tenderlovemaking.com>
|
2
|
+
|
3
|
+
* ext/psych/lib/psych/visitors/to_ruby.rb: call `allocate` on hash
|
4
|
+
subclasses. Fixes github.com/tenderlove/psych/issues/196
|
5
|
+
|
6
|
+
* test/psych/test_hash.rb: test for change
|
7
|
+
|
8
|
+
Fri Jan 9 06:58:43 2015 Aaron Patterson <aaron@tenderlovemaking.com>
|
9
|
+
|
10
|
+
* ext/psych/lib/psych/visitors/to_ruby.rb: revive hashes with ivars
|
11
|
+
|
12
|
+
* ext/psych/lib/psych/visitors/yaml_tree.rb: dump hashes with ivars.
|
13
|
+
Fixes github.com/psych/issues/43
|
14
|
+
|
15
|
+
* test/psych/test_hash.rb: test for change
|
16
|
+
|
1
17
|
Sun Nov 23 13:11:24 2014 Sean Griffin <sean@thoughtbot.com>
|
2
18
|
|
3
19
|
* lib/psych/visitors/to_ruby.rb: Allow loading any BasicObject that
|
data/Rakefile
CHANGED
@@ -9,9 +9,10 @@ class Hoe
|
|
9
9
|
end
|
10
10
|
|
11
11
|
gem 'rake-compiler', '>= 0.4.1'
|
12
|
+
gem 'minitest', '~> 4.0'
|
12
13
|
require "rake/extensiontask"
|
13
14
|
|
14
|
-
Hoe.plugin :doofus, :git, :gemspec
|
15
|
+
Hoe.plugin :doofus, :git, :gemspec
|
15
16
|
|
16
17
|
$hoe = Hoe.spec 'psych' do
|
17
18
|
license 'MIT'
|
@@ -23,6 +24,7 @@ $hoe = Hoe.spec 'psych' do
|
|
23
24
|
self.testlib = :minitest
|
24
25
|
|
25
26
|
extra_dev_deps << ['rake-compiler', '>= 0.4.1']
|
27
|
+
extra_dev_deps << ['minitest', '~> 4.0']
|
26
28
|
|
27
29
|
self.spec_extras = {
|
28
30
|
:extensions => ["ext/psych/extconf.rb"],
|
data/lib/psych.rb
CHANGED
@@ -261,8 +261,22 @@ module Psych
|
|
261
261
|
end
|
262
262
|
set
|
263
263
|
|
264
|
+
when /^!ruby\/hash-with-ivars(?::(.*))?$/
|
265
|
+
hash = $1 ? resolve_class($1).allocate : {}
|
266
|
+
o.children.each_slice(2) do |key, value|
|
267
|
+
case key.value
|
268
|
+
when 'elements'
|
269
|
+
revive_hash hash, value
|
270
|
+
when 'ivars'
|
271
|
+
value.children.each_slice(2) do |k,v|
|
272
|
+
hash.instance_variable_set accept(k), accept(v)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
276
|
+
hash
|
277
|
+
|
264
278
|
when /^!map:(.*)$/, /^!ruby\/hash:(.*)$/
|
265
|
-
revive_hash register(o, resolve_class($1).
|
279
|
+
revive_hash register(o, resolve_class($1).allocate), o
|
266
280
|
|
267
281
|
when '!omap', 'tag:yaml.org,2002:omap'
|
268
282
|
map = register(o, class_loader.psych_omap.new)
|
@@ -317,7 +317,7 @@ module Psych
|
|
317
317
|
tag = 'tag:yaml.org,2002:str'
|
318
318
|
plain = false
|
319
319
|
quote = false
|
320
|
-
elsif o =~
|
320
|
+
elsif o =~ /^[^[:word:]][^"]*$/
|
321
321
|
style = Nodes::Scalar::DOUBLE_QUOTED
|
322
322
|
else
|
323
323
|
unless String === @ss.tokenize(o)
|
@@ -367,17 +367,46 @@ module Psych
|
|
367
367
|
end
|
368
368
|
|
369
369
|
def visit_Hash o
|
370
|
-
|
371
|
-
implicit = !tag
|
370
|
+
ivars = o.instance_variables
|
372
371
|
|
373
|
-
|
372
|
+
if ivars.any?
|
373
|
+
tag = "!ruby/hash-with-ivars"
|
374
|
+
tag << ":#{o.class}" unless o.class == ::Hash
|
374
375
|
|
375
|
-
|
376
|
-
accept k
|
377
|
-
accept v
|
378
|
-
end
|
376
|
+
register(o, @emitter.start_mapping(nil, tag, false, Psych::Nodes::Mapping::BLOCK))
|
379
377
|
|
380
|
-
|
378
|
+
@emitter.scalar 'elements', nil, nil, true, false, Nodes::Scalar::ANY
|
379
|
+
|
380
|
+
@emitter.start_mapping nil, nil, true, Nodes::Mapping::BLOCK
|
381
|
+
o.each do |k,v|
|
382
|
+
accept k
|
383
|
+
accept v
|
384
|
+
end
|
385
|
+
@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
|
+
else
|
398
|
+
tag = o.class == ::Hash ? nil : "!ruby/hash:#{o.class}"
|
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
|
409
|
+
end
|
381
410
|
end
|
382
411
|
|
383
412
|
def visit_Psych_Set o
|
data/test/psych/test_hash.rb
CHANGED
@@ -5,11 +5,55 @@ module Psych
|
|
5
5
|
class X < Hash
|
6
6
|
end
|
7
7
|
|
8
|
+
class HashWithCustomInit < Hash
|
9
|
+
attr_reader :obj
|
10
|
+
def initialize(obj)
|
11
|
+
@obj = obj
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class HashWithCustomInitNoIvar < Hash
|
16
|
+
def initialize(obj)
|
17
|
+
# *shrug*
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
8
21
|
def setup
|
9
22
|
super
|
10
23
|
@hash = { :a => 'b' }
|
11
24
|
end
|
12
25
|
|
26
|
+
def test_custom_initialized
|
27
|
+
a = [1,2,3,4,5]
|
28
|
+
t1 = HashWithCustomInit.new(a)
|
29
|
+
t2 = Psych.load(Psych.dump(t1))
|
30
|
+
assert_equal t1, t2
|
31
|
+
assert_cycle t1
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_custom_initialize_no_ivar
|
35
|
+
t1 = HashWithCustomInitNoIvar.new(nil)
|
36
|
+
t2 = Psych.load(Psych.dump(t1))
|
37
|
+
assert_equal t1, t2
|
38
|
+
assert_cycle t1
|
39
|
+
end
|
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
|
+
def test_hash_subclass_with_ivars
|
48
|
+
x = X.new
|
49
|
+
x[:a] = 'b'
|
50
|
+
x.instance_variable_set :@foo, 'bar'
|
51
|
+
dup = Psych.load Psych.dump x
|
52
|
+
assert_cycle x
|
53
|
+
assert_equal 'bar', dup.instance_variable_get(:@foo)
|
54
|
+
assert_equal X, dup.class
|
55
|
+
end
|
56
|
+
|
13
57
|
def test_load_with_class_syck_compatibility
|
14
58
|
hash = Psych.load "--- !ruby/object:Hash\n:user_id: 7\n:username: Lucas\n"
|
15
59
|
assert_equal({ user_id: 7, username: 'Lucas'}, hash)
|
data/test/psych/test_string.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
require_relative 'helper'
|
2
3
|
|
3
4
|
module Psych
|
@@ -23,6 +24,11 @@ module Psych
|
|
23
24
|
assert_equal 2, Psych.dump(%Q{<%= ENV["PATH"] %>}).count('"')
|
24
25
|
end
|
25
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
|
+
|
26
32
|
def test_doublequotes_when_there_is_a_single
|
27
33
|
yaml = Psych.dump "@123'abc"
|
28
34
|
assert_match(/---\s*"/, yaml)
|
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.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Patterson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdoc
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.4.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: hoe
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|