mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/psych] Fix custom marshalization with symbolize_names: true
https://github.com/ruby/psych/commit/ee26f26ab5
This commit is contained in:
parent
155cd7fd2a
commit
c110ade0d2
2 changed files with 11 additions and 3 deletions
|
@ -339,7 +339,7 @@ module Psych
|
||||||
list
|
list
|
||||||
end
|
end
|
||||||
|
|
||||||
def revive_hash hash, o
|
def revive_hash hash, o, tagged= false
|
||||||
o.children.each_slice(2) { |k,v|
|
o.children.each_slice(2) { |k,v|
|
||||||
key = accept(k)
|
key = accept(k)
|
||||||
val = accept(v)
|
val = accept(v)
|
||||||
|
@ -366,7 +366,7 @@ module Psych
|
||||||
hash[key] = val
|
hash[key] = val
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if @symbolize_names
|
if !tagged && @symbolize_names
|
||||||
key = key.to_sym
|
key = key.to_sym
|
||||||
elsif !@freeze
|
elsif !@freeze
|
||||||
key = deduplicate(key)
|
key = deduplicate(key)
|
||||||
|
@ -404,7 +404,7 @@ module Psych
|
||||||
|
|
||||||
def revive klass, node
|
def revive klass, node
|
||||||
s = register(node, klass.allocate)
|
s = register(node, klass.allocate)
|
||||||
init_with(s, revive_hash({}, node), node)
|
init_with(s, revive_hash({}, node, true), node)
|
||||||
end
|
end
|
||||||
|
|
||||||
def init_with o, h, node
|
def init_with o, h, node
|
||||||
|
|
|
@ -51,5 +51,13 @@ module Psych
|
||||||
assert(PsychCustomMarshalable === loaded)
|
assert(PsychCustomMarshalable === loaded)
|
||||||
assert_equal(2, loaded.foo)
|
assert_equal(2, loaded.foo)
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue