summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2021-02-11 18:30:58 +0100
committerJean Boussier <jean.boussier@gmail.com>2021-02-15 10:18:46 +0100
commitee26f26ab5e39eec402ea01109b9ba736d06b5b6 (patch)
treef4c5f9f7b918131ccdc7c920b3d24f00e66dd299
parentfeeb22416544dca70021874e83ff6e94c1730ef5 (diff)
downloadpsych-ee26f26ab5e39eec402ea01109b9ba736d06b5b6.zip
Fix custom marshalization with symbolize_names: true
-rw-r--r--lib/psych/visitors/to_ruby.rb6
-rw-r--r--test/psych/test_marshalable.rb8
2 files changed, 11 insertions, 3 deletions
diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb
index a100188..4d98850 100644
--- a/lib/psych/visitors/to_ruby.rb
+++ b/lib/psych/visitors/to_ruby.rb
@@ -339,7 +339,7 @@ module Psych
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
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
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
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