diff options
author | Jean Boussier <jean.boussier@gmail.com> | 2021-09-01 09:43:39 +0100 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-09-15 08:00:18 +0900 |
commit | 89242279e61b023a81c58065c62a82de8829d0b3 (patch) | |
tree | 25cb8c6e3520470c94c633e80e4b3bb4b192a1f5 /test/ruby | |
parent | a0357acf197dcdb504dd97af39103dd8c68f53b3 (diff) | |
download | ruby-89242279e61b023a81c58065c62a82de8829d0b3.tar.gz |
Marshal.load: do not call the proc until strings have their encoding
Ref: https://bugs.ruby-lang.org/issues/18141
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_marshal.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/ruby/test_marshal.rb b/test/ruby/test_marshal.rb index 5e6891a6a0..a0d9d96a1f 100644 --- a/test/ruby/test_marshal.rb +++ b/test/ruby/test_marshal.rb @@ -676,6 +676,23 @@ class TestMarshal < Test::Unit::TestCase assert_equal(['X', 'X'], Marshal.load(Marshal.dump(obj), ->(v) { v == str ? v.upcase : v })) end + def test_marshal_proc_string_encoding + string = "foo" + payload = Marshal.dump(string) + Marshal.load(payload, ->(v) { + if v.is_a?(String) + assert_equal(string, v) + assert_equal(string.encoding, v.encoding) + end + v + }) + end + + def test_marshal_proc_freeze + object = { foo: [42, "bar"] } + assert_equal object, Marshal.load(Marshal.dump(object), :freeze.to_proc) + end + def test_marshal_load_extended_class_crash assert_separately([], "#{<<-"begin;"}\n#{<<-"end;"}") begin; |