Permalink
Browse files

Added regression spec about Marshal.load for JRUBY-5223

  • Loading branch information...
1 parent 88ad204 commit ea48d8d9d5b29e6cef2f149f9965b05dc74a8037 @nahi nahi committed Dec 1, 2010
Showing with 50 additions and 0 deletions.
  1. +50 −0 spec/regression/JRUBY-5223_marshal_load_spec.rb
View
50 spec/regression/JRUBY-5223_marshal_load_spec.rb
@@ -0,0 +1,50 @@
+require 'stringio'
+
+describe "Marshal load behavior: JRUBY-5223" do
+ before(:each) do
+ @obj = [1, 2, 3]
+ @src = Marshal.dump(@obj)
+ end
+
+ it "should load string" do
+ obj = Marshal.load(@src)
+ obj.should == @obj
+ obj.tainted?.should == false
+ end
+
+ it "should propagate taintness" do
+ @src.taint
+ obj = Marshal.load(@src)
+ obj.should == @obj
+ obj.tainted?.should == true
+ end
+
+ it "should load IO" do
+ obj = Marshal.load(StringIO.new(@src))
+ obj.should == @obj
+ obj.tainted?.should == true
+ end
+
+ it "should load string if it responds to :read" do
+ def @src.read; end
+ obj = Marshal.load(@src)
+ obj.should == @obj
+ end
+
+ it "should try stringify with to_str" do
+ dummy_src = Object.new
+ def dummy_src.to_str
+ Marshal.dump([1, 2, 3])
+ end
+ obj = Marshal.load(dummy_src)
+ obj.should == @obj
+ end
+
+ it "should try to set binmode if it seems IO" do
+ dummy_src = StringIO.new(@src)
+ def dummy_src.binmode; raise; end
+ proc {
+ Marshal.load(dummy_src)
+ }.should raise_error RuntimeError
+ end
+end

0 comments on commit ea48d8d

Please sign in to comment.