psych 2.0.8 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9f4c0db7eb15a38300a2e0b67f1a7ed0684f1f04
4
- data.tar.gz: f93f68a1a66f579da0f09def436544d5becdad70
3
+ metadata.gz: ff8cb5130ddeec957e2ea9cb3743aff24dba4dc9
4
+ data.tar.gz: 71ee9f61849d041bea7f7e7ffb90f380d315eaab
5
5
  SHA512:
6
- metadata.gz: a1fc55b8c18c01b5cebec82f87e9e767ae2aaf9332d72c876f8b848f489001f307c4020c7730d32afd38c63f0a444da4371c11d3bfd8e3836a78482e1e531c0c
7
- data.tar.gz: 3e1e6663119da44e991eeba5391945d0443feaeaf9c72a43053d6cda0887bbf735cd3a040eb8da48634d9b41a01ab917b09aa29156c59ccb01f3ef8b026e0f1b
6
+ metadata.gz: 9641a5d5820bee5cb15db5c768e094ec5158b3c7f7d2ec4f1e91933f046cb129b6c316339e8293cac73eb34100ca901a90c029341ca5053d47a1d531753d1efc
7
+ data.tar.gz: 7e270db26bdd10fef4c1c809f780f23699a2196a16cb3f394d1ee9a7c48f8ef57184fe805c125f30dc89d428eb833c50fbb2935b95dad308cfc990d09b7025d5
@@ -3,8 +3,9 @@ rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
5
  - 2.1.0
6
+ - ruby-head
6
7
  before_script:
7
- - gem install isolate
8
8
  - gem install hoe
9
9
  - gem install rake-compiler
10
- script: rake isolate test
10
+ - gem install minitest -v '~> 4.0'
11
+ script: rake test
@@ -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, :isolate
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"],
@@ -217,7 +217,7 @@ require 'psych/class_loader'
217
217
 
218
218
  module Psych
219
219
  # The version is Psych you're using
220
- VERSION = '2.0.8'
220
+ VERSION = '2.0.9'
221
221
 
222
222
  # The version of libyaml Psych is using
223
223
  LIBYAML_VERSION = Psych.libyaml_version.join '.'
@@ -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).new), o
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 =~ /^\W[^"]*$/
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
- tag = o.class == ::Hash ? nil : "!ruby/hash:#{o.class}"
371
- implicit = !tag
370
+ ivars = o.instance_variables
372
371
 
373
- register(o, @emitter.start_mapping(nil, tag, implicit, Psych::Nodes::Mapping::BLOCK))
372
+ if ivars.any?
373
+ tag = "!ruby/hash-with-ivars"
374
+ tag << ":#{o.class}" unless o.class == ::Hash
374
375
 
375
- o.each do |k,v|
376
- accept k
377
- accept v
378
- end
376
+ register(o, @emitter.start_mapping(nil, tag, false, Psych::Nodes::Mapping::BLOCK))
379
377
 
380
- @emitter.end_mapping
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
@@ -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)
@@ -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.8
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: 2014-12-05 00:00:00.000000000 Z
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