1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/psych] Fix anchor lookup with symbolized names

https://github.com/ruby/psych/commit/ef74fc01e2
This commit is contained in:
Jean Boussier 2020-06-08 17:52:41 +02:00 committed by Hiroshi SHIBATA
parent e9adc2f420
commit 666c077691
No known key found for this signature in database
GPG key ID: F9CF13417264FAC2
2 changed files with 17 additions and 7 deletions

View file

@ -337,18 +337,12 @@ module Psych
list
end
SHOVEL = '<<'
def revive_hash hash, o
o.children.each_slice(2) { |k,v|
key = accept(k)
if @symbolize_names
key = key.to_sym
elsif !@freeze
key = deduplicate(key)
end
val = accept(v)
if key == SHOVEL && k.tag != "tag:yaml.org,2002:str"
if key == '<<' && k.tag != "tag:yaml.org,2002:str"
case v
when Nodes::Alias, Nodes::Mapping
begin
@ -370,6 +364,12 @@ module Psych
hash[key] = val
end
else
if @symbolize_names
key = key.to_sym
elsif !@freeze
key = deduplicate(key)
end
hash[key] = val
end

View file

@ -17,6 +17,16 @@ map:
assert_equal hash, doc
end
def test_merge_key_with_bare_hash_symbolized_names
doc = Psych.load <<-eodoc, symbolize_names: true
map:
<<:
hello: world
eodoc
hash = { map: { hello: "world" } }
assert_equal hash, doc
end
def test_roundtrip_with_chevron_key
h = {}
v = { 'a' => h, '<<' => h }