summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2021-09-01 09:43:39 +0100
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-09-15 08:00:18 +0900
commit89242279e61b023a81c58065c62a82de8829d0b3 (patch)
tree25cb8c6e3520470c94c633e80e4b3bb4b192a1f5 /test
parenta0357acf197dcdb504dd97af39103dd8c68f53b3 (diff)
Marshal.load: do not call the proc until strings have their encoding
Ref: https://bugs.ruby-lang.org/issues/18141
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4797
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_marshal.rb17
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;