summaryrefslogtreecommitdiff
path: root/ext/psych/lib
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-05 17:11:21 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-05 17:11:21 +0000
commit7a7bb6446410c239c7f92bd8e94f235f349206ea (patch)
treed6e504bb55d03eb8b43caf8c51cc90456b508840 /ext/psych/lib
parentfbb29bc08c76c00b963e5587e8e9e4b7c580ea95 (diff)
* ext/psych/lib/psych/visitors/to_ruby.rb: correctly register
self-referential strings. Fixes tenderlove/psych #135 * test/psych/test_string.rb: appropriate test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40137 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/psych/lib')
-rw-r--r--ext/psych/lib/psych/visitors/to_ruby.rb24
1 files changed, 17 insertions, 7 deletions
diff --git a/ext/psych/lib/psych/visitors/to_ruby.rb b/ext/psych/lib/psych/visitors/to_ruby.rb
index 9ccf420c34..b59bc38830 100644
--- a/ext/psych/lib/psych/visitors/to_ruby.rb
+++ b/ext/psych/lib/psych/visitors/to_ruby.rb
@@ -180,15 +180,25 @@ module Psych
end
when /^!(?:str|ruby\/string)(?::(.*))?/, 'tag:yaml.org,2002:str'
- klass = resolve_class($1)
- members = Hash[*o.children.map { |c| accept c }]
- string = members.delete 'str'
+ klass = resolve_class($1)
+ members = {}
+ string = nil
- if klass
- string = klass.allocate.replace string
- register(o, string)
- end
+ o.children.each_slice(2) do |k,v|
+ key = accept k
+ value = accept v
+ if key == 'str'
+ if klass
+ string = klass.allocate.replace value
+ else
+ string = value
+ end
+ register(o, string)
+ else
+ members[key] = value
+ end
+ end
init_with(string, members.map { |k,v| [k.to_s.sub(/^@/, ''),v] }, o)
when /^!ruby\/array:(.*)$/
klass = resolve_class($1)