ruby-changes:61908
From: Jean <ko1@a...>
Date: Tue, 23 Jun 2020 15:26:51 +0900 (JST)
Subject: [ruby-changes:61908] 666c077691 (master): [ruby/psych] Fix anchor lookup with symbolized names
https://git.ruby-lang.org/ruby.git/commit/?id=666c077691 From 666c077691a5521cb82254911f0abb9575cac9a1 Mon Sep 17 00:00:00 2001 From: Jean Boussier <jean.boussier@g...> Date: Mon, 8 Jun 2020 17:52:41 +0200 Subject: [ruby/psych] Fix anchor lookup with symbolized names https://github.com/ruby/psych/commit/ef74fc01e2 diff --git a/ext/psych/lib/psych/visitors/to_ruby.rb b/ext/psych/lib/psych/visitors/to_ruby.rb index a922f90..ec80701 100644 --- a/ext/psych/lib/psych/visitors/to_ruby.rb +++ b/ext/psych/lib/psych/visitors/to_ruby.rb @@ -337,18 +337,12 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/visitors/to_ruby.rb#L337 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 https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/visitors/to_ruby.rb#L364 hash[key] = val end else + if @symbolize_names + key = key.to_sym + elsif !@freeze + key = deduplicate(key) + end + hash[key] = val end diff --git a/test/psych/test_merge_keys.rb b/test/psych/test_merge_keys.rb index 1bc3dd1..08ffe58 100644 --- a/test/psych/test_merge_keys.rb +++ b/test/psych/test_merge_keys.rb @@ -17,6 +17,16 @@ map: https://github.com/ruby/ruby/blob/trunk/test/psych/test_merge_keys.rb#L17 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 } -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/