From 962415e09ed98c378dd6cb4bd629b2710aa3c032 Mon Sep 17 00:00:00 2001 From: Herwin Date: Sun, 29 Sep 2024 12:08:33 +0200 Subject: [PATCH] Raise an exception for Marshal.dump of a singleton class --- spec/core/marshal/dump_spec.rb | 4 +--- src/marshal.rb | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/spec/core/marshal/dump_spec.rb b/spec/core/marshal/dump_spec.rb index 5be7b74f3..c2bfdc034 100644 --- a/spec/core/marshal/dump_spec.rb +++ b/spec/core/marshal/dump_spec.rb @@ -233,9 +233,7 @@ def _dump(level) end it "raises TypeError with a singleton Class" do - NATFIXME 'raises TypeError with a singleton Class', exception: SpecFailedException do - -> { Marshal.dump(class << self; self end) }.should raise_error(TypeError) - end + -> { Marshal.dump(class << self; self end) }.should raise_error(TypeError) end end diff --git a/src/marshal.rb b/src/marshal.rb index eb36abdec..badd0995f 100644 --- a/src/marshal.rb +++ b/src/marshal.rb @@ -219,6 +219,7 @@ def write_hash(values) end def write_class(value) + raise TypeError, "singleton class can't be dumped" if value.singleton_class? write_char('c') write_string_bytes(value.name) end