Project

General

Profile

Feature #12017 ยป 0001-dedupe-string-keys-from-Marshal.load.patch

normalperson (Eric Wong), 01/25/2016 09:02 AM

View differences:

marshal.c
while (len--) {
VALUE key = r_object(arg);
VALUE value = r_object(arg);
if (rb_obj_class(key) == rb_cString) {
key = rb_fstring(key);
}
rb_hash_aset(v, key, value);
arg->readable -= 2;
}
test/ruby/test_marshal.rb
obj = [str, str]
assert_equal(['X', 'X'], Marshal.load(Marshal.dump(obj), ->(v) { v == str ? v.upcase : v }))
end
def test_hash_key_dedup
orig = { 'foo' => 1, 'bar' => 2 }
loaded = Marshal.load(Marshal.dump(orig))
assert_equal orig, loaded
assert_equal orig.keys.map(&:object_id).sort,
loaded.keys.map(&:object_id).sort
end
end
-
    (1-1/1)