Skip to content

Commit ee26f26

Browse files
committed
Fix custom marshalization with symbolize_names: true
1 parent feeb224 commit ee26f26

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/psych/visitors/to_ruby.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def register_empty object
339339
list
340340
end
341341

342-
def revive_hash hash, o
342+
def revive_hash hash, o, tagged= false
343343
o.children.each_slice(2) { |k,v|
344344
key = accept(k)
345345
val = accept(v)
@@ -366,7 +366,7 @@ def revive_hash hash, o
366366
hash[key] = val
367367
end
368368
else
369-
if @symbolize_names
369+
if !tagged && @symbolize_names
370370
key = key.to_sym
371371
elsif !@freeze
372372
key = deduplicate(key)
@@ -404,7 +404,7 @@ def merge_key hash, key, val
404404

405405
def revive klass, node
406406
s = register(node, klass.allocate)
407-
init_with(s, revive_hash({}, node), node)
407+
init_with(s, revive_hash({}, node, true), node)
408408
end
409409

410410
def init_with o, h, node

test/psych/test_marshalable.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,13 @@ def test_init_with_takes_priority_over_marshal_methods
5151
assert(PsychCustomMarshalable === loaded)
5252
assert_equal(2, loaded.foo)
5353
end
54+
55+
def test_init_symbolize_names
56+
obj = PsychCustomMarshalable.new(1)
57+
loaded = Psych.load(Psych.dump(obj), symbolize_names: true)
58+
59+
assert(PsychCustomMarshalable === loaded)
60+
assert_equal(2, loaded.foo)
61+
end
5462
end
5563
end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy