ruby-changes:66123
From: Jean <ko1@a...>
Date: Mon, 10 May 2021 19:20:01 +0900 (JST)
Subject: [ruby-changes:66123] c110ade0d2 (master): [ruby/psych] Fix custom marshalization with symbolize_names: true
https://git.ruby-lang.org/ruby.git/commit/?id=c110ade0d2 From c110ade0d235391c2fbfe9291250f744b735a1a8 Mon Sep 17 00:00:00 2001 From: Jean Boussier <jean.boussier@g...> Date: Thu, 11 Feb 2021 18:30:58 +0100 Subject: [ruby/psych] Fix custom marshalization with symbolize_names: true https://github.com/ruby/psych/commit/ee26f26ab5 --- ext/psych/lib/psych/visitors/to_ruby.rb | 6 +++--- test/psych/test_marshalable.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ext/psych/lib/psych/visitors/to_ruby.rb b/ext/psych/lib/psych/visitors/to_ruby.rb index a100188..4d98850 100644 --- a/ext/psych/lib/psych/visitors/to_ruby.rb +++ b/ext/psych/lib/psych/visitors/to_ruby.rb @@ -339,7 +339,7 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/visitors/to_ruby.rb#L339 list end - def revive_hash hash, o + def revive_hash hash, o, tagged= false o.children.each_slice(2) { |k,v| key = accept(k) val = accept(v) @@ -366,7 +366,7 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/visitors/to_ruby.rb#L366 hash[key] = val end else - if @symbolize_names + if !tagged && @symbolize_names key = key.to_sym elsif !@freeze key = deduplicate(key) @@ -404,7 +404,7 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/visitors/to_ruby.rb#L404 def revive klass, node s = register(node, klass.allocate) - init_with(s, revive_hash({}, node), node) + init_with(s, revive_hash({}, node, true), node) end def init_with o, h, node diff --git a/test/psych/test_marshalable.rb b/test/psych/test_marshalable.rb index b1f4a83..152cc4e 100644 --- a/test/psych/test_marshalable.rb +++ b/test/psych/test_marshalable.rb @@ -51,5 +51,13 @@ module Psych https://github.com/ruby/ruby/blob/trunk/test/psych/test_marshalable.rb#L51 assert(PsychCustomMarshalable === loaded) assert_equal(2, loaded.foo) end + + def test_init_symbolize_names + obj = PsychCustomMarshalable.new(1) + loaded = Psych.load(Psych.dump(obj), symbolize_names: true) + + assert(PsychCustomMarshalable === loaded) + assert_equal(2, loaded.foo) + end end end -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/