ruby-changes:20554
From: marcandre <ko1@a...>
Date: Fri, 22 Jul 2011 07:07:16 +0900 (JST)
Subject: [ruby-changes:20554] marcandRe: r32602 (ruby_1_9_3): * backport of r32600 from trunk
marcandre 2011-07-22 06:40:21 +0900 (Fri, 22 Jul 2011) New Revision: 32602 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32602 Log: * backport of r32600 from trunk * lib/csv.rb: Do not modify CSV.generate's argument [ruby-core:38356] Modified files: branches/ruby_1_9_3/ChangeLog branches/ruby_1_9_3/lib/csv.rb branches/ruby_1_9_3/test/csv/test_interface.rb Index: ruby_1_9_3/ChangeLog =================================================================== --- ruby_1_9_3/ChangeLog (revision 32601) +++ ruby_1_9_3/ChangeLog (revision 32602) @@ -1,3 +1,7 @@ +Fri Jul 22 06:39:34 2011 Marc-Andre Lafortune <ruby-core@m...> + + * lib/csv.rb: Do not modify CSV.generate's argument [ruby-core:38356] + Thu Jul 21 20:02:11 2011 Yusuke Endoh <mame@t...> * thread.c (set_trace_func, thread_set_trace_func_m): reset tracing Index: ruby_1_9_3/lib/csv.rb =================================================================== --- ruby_1_9_3/lib/csv.rb (revision 32601) +++ ruby_1_9_3/lib/csv.rb (revision 32602) @@ -1234,7 +1234,7 @@ io.seek(0, IO::SEEK_END) args.unshift(io) else - encoding = args.last.is_a?(Hash) ? args.last.delete(:encoding) : nil + encoding = (args[-1] = args[-1].dup).delete(:encoding) if args.last.is_a?(Hash) str = "" str.encode!(encoding) if encoding args.unshift(str) Index: ruby_1_9_3/test/csv/test_interface.rb =================================================================== --- ruby_1_9_3/test/csv/test_interface.rb (revision 32601) +++ ruby_1_9_3/test/csv/test_interface.rb (revision 32602) @@ -316,4 +316,19 @@ assert_equal(STDOUT, CSV.instance.instance_eval { @io }) assert_equal(STDOUT, CSV { |new_csv| new_csv.instance_eval { @io } }) end + + def test_options_are_not_modified + opt = {}.freeze + assert_nothing_raised { CSV.foreach(@path, opt) } + assert_nothing_raised { CSV.open(@path, opt){} } + assert_nothing_raised { CSV.parse("", opt) } + assert_nothing_raised { CSV.parse_line("", opt) } + assert_nothing_raised { CSV.read(@path, opt) } + assert_nothing_raised { CSV.readlines(@path, opt) } + assert_nothing_raised { CSV.table(@path, opt) } + assert_nothing_raised { CSV.generate(opt){} } + assert_nothing_raised { CSV.generate_line([], opt) } + assert_nothing_raised { CSV.filter("", "", opt){} } + assert_nothing_raised { CSV.instance("", opt) } + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/