From e81fab537fb61eb368f52dcfafccb55e1e376bdc Mon Sep 17 00:00:00 2001 From: Steven Luscher Date: Mon, 6 Apr 2009 20:47:23 -0700 Subject: [PATCH] Fixes #2439. ActionController::Integration::Session no longer mangles multiparameter attribute params when processing multipart requests. --- actionpack/lib/action_controller/integration.rb | 2 +- actionpack/test/controller/integration_test.rb | 28 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletions(-) diff --git a/actionpack/lib/action_controller/integration.rb b/actionpack/lib/action_controller/integration.rb index fda6b63..db175f5 100644 --- a/actionpack/lib/action_controller/integration.rb +++ b/actionpack/lib/action_controller/integration.rb @@ -418,7 +418,7 @@ module ActionController def multipart_requestify(params, first=true) returning Hash.new do |p| params.each do |key, value| - k = first ? CGI.escape(key.to_s) : "[#{CGI.escape(key.to_s)}]" + k = first ? key.to_s : "[#{key.to_s}]" if Hash === value multipart_requestify(value, false).each do |subkey, subvalue| p[k + subkey] = subvalue diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index e39a934..8384250 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -239,6 +239,14 @@ class IntegrationProcessTest < ActionController::IntegrationTest def get_with_params render :text => "foo: #{params[:foo]}", :status => 200 end + + def post_with_multiparameter_params + render :text => "foo(1i): #{params[:"foo(1i)"]}, foo(2i): #{params[:"foo(2i)"]}", :status => 200 + end + + def multipart_post_with_multiparameter_params + render :text => "foo(1i): #{params[:"foo(1i)"]}, foo(2i): #{params[:"foo(2i)"]}, filesize: #{params[:file].size}", :status => 200 + end def post render :text => "Created", :status => 201 @@ -255,6 +263,8 @@ class IntegrationProcessTest < ActionController::IntegrationTest end end + FILES_DIR = File.dirname(__FILE__) + '/../fixtures/multipart' + def test_get with_test_route_set do get '/get' @@ -359,6 +369,24 @@ class IntegrationProcessTest < ActionController::IntegrationTest assert_equal "foo: bar", response.body end end + + def test_post_with_multiparameter_attribute_parameters + with_test_route_set do + post '/post_with_multiparameter_params', :"foo(1i)" => "bar", :"foo(2i)" => "baz" + + assert_equal 200, status + assert_equal "foo(1i): bar, foo(2i): baz", response.body + end + end + + def test_multipart_post_with_multiparameter_attribute_parameters + with_test_route_set do + post '/multipart_post_with_multiparameter_params', :"foo(1i)" => "bar", :"foo(2i)" => "baz", :file => fixture_file_upload(FILES_DIR + "/mona_lisa.jpg", "image/jpg") + + assert_equal 200, status + assert_equal "foo(1i): bar, foo(2i): baz, filesize: 159528", response.body + end + end def test_head with_test_route_set do -- 1.6.0.2