Skip to content

Commit

Permalink
Fix custom marshalization with symbolize_names: true
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Feb 15, 2021
1 parent feeb224 commit ee26f26
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/psych/visitors/to_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def register_empty object
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)
Expand All @@ -366,7 +366,7 @@ def revive_hash hash, o
hash[key] = val
end
else
if @symbolize_names
if !tagged && @symbolize_names
key = key.to_sym
elsif !@freeze
key = deduplicate(key)
Expand Down Expand Up @@ -404,7 +404,7 @@ def merge_key hash, key, val

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
Expand Down
8 changes: 8 additions & 0 deletions test/psych/test_marshalable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,13 @@ def test_init_with_takes_priority_over_marshal_methods
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

0 comments on commit ee26f26

Please sign in to comment.