aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--lib/csv.rb4
-rwxr-xr-xtest/csv/test_interface.rb6
3 files changed, 15 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index eb6e7b0a8f..e33c5ddd2d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon May 26 01:39:02 2014 Zachary Scott <e@zzak.io>
+
+ * lib/csv.rb: Reject nil as data source for CSV.new, patch by @Peeja.
+ [Fixes GH-580] https://github.com/ruby/ruby/pull/580
+
Mon May 26 01:07:51 2014 Tanaka Akira <akr@fsij.org>
* test/lib/minitest/unit.rb: Show leaked threads and tempfiles
diff --git a/lib/csv.rb b/lib/csv.rb
index cd59d8caeb..595586a541 100644
--- a/lib/csv.rb
+++ b/lib/csv.rb
@@ -1484,6 +1484,10 @@ class CSV
# so be sure to set what you want here.
#
def initialize(data, options = Hash.new)
+ if data.nil?
+ raise ArgumentError.new("Cannot parse nil as CSV")
+ end
+
# build the options for this read/write
options = DEFAULT_OPTIONS.merge(options)
diff --git a/test/csv/test_interface.rb b/test/csv/test_interface.rb
index 89b4a462f9..d6bf470f6b 100755
--- a/test/csv/test_interface.rb
+++ b/test/csv/test_interface.rb
@@ -130,6 +130,12 @@ class TestCSV::Interface < TestCSV
end
end
+ def test_nil_is_not_acceptable
+ assert_raise_with_message ArgumentError, "Cannot parse nil as CSV" do
+ CSV.new(nil)
+ end
+ end
+
### Test Write Interface ###
def test_generate