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
1770 1770
	    while (len--) {
1771 1771
		VALUE key = r_object(arg);
1772 1772
		VALUE value = r_object(arg);
1773

  
1774
		if (rb_obj_class(key) == rb_cString) {
1775
		    key = rb_fstring(key);
1776
		}
1773 1777
		rb_hash_aset(v, key, value);
1774 1778
		arg->readable -= 2;
1775 1779
	    }
test/ruby/test_marshal.rb
718 718
    obj = [str, str]
719 719
    assert_equal(['X', 'X'], Marshal.load(Marshal.dump(obj), ->(v) { v == str ? v.upcase : v }))
720 720
  end
721

  
722
  def test_hash_key_dedup
723
    orig = { 'foo' => 1, 'bar' => 2 }
724
    loaded = Marshal.load(Marshal.dump(orig))
725
    assert_equal orig, loaded
726
    assert_equal orig.keys.map(&:object_id).sort,
727
                 loaded.keys.map(&:object_id).sort
728
  end
721 729
end
722
-