Skip to content

Commit

Permalink
Merge pull request #2384 from herwinw/marshal_dump_typeerror
Browse files Browse the repository at this point in the history
Raise TypeError if _dump returns a non-string
  • Loading branch information
herwinw committed Dec 13, 2024
2 parents c60a4a6 + 40e92ee commit 274836b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
6 changes: 2 additions & 4 deletions spec/core/marshal/dump_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,8 @@

it "raises a TypeError if _dump returns a non-string" do
m = mock("marshaled")
NATFIXME 'raises a TypeError if _dump returns a non-string', exception: SpecFailedException do
m.should_receive(:_dump).and_return(0)
-> { Marshal.dump(m) }.should raise_error(TypeError)
end
m.should_receive(:_dump).and_return(0)
-> { Marshal.dump(m) }.should raise_error(TypeError)
end

it "raises TypeError if an Object is an instance of an anonymous class" do
Expand Down
1 change: 1 addition & 0 deletions src/marshal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ def write_user_marshaled_object_without_allocate(value)
write_char('u')
write(value.class.to_s.to_sym)
dump = value.send(:_dump, -1)
raise TypeError, '_dump() must return string' unless dump.is_a?(String)
write_integer_bytes(dump.size)
write_bytes(value.send(:_dump, -1))
end
Expand Down

0 comments on commit 274836b

Please sign in to comment.