aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMislav Marohnić <mislav.marohnic@gmail.com>2009-01-20 12:38:25 -0600
committerJoshua Peek <josh@joshpeek.com>2009-01-20 12:38:25 -0600
commit01f06fc7f4dda52035d5a2273d402d8555a897a5 (patch)
treef565edb0adde7dcb43d09b7e043d3aa827ce1d46
parentc090e5e0755bea3a7cd7135329f8dae6094810b6 (diff)
downloadrails-01f06fc7f4dda52035d5a2273d402d8555a897a5.tar.gz
rails-01f06fc7f4dda52035d5a2273d402d8555a897a5.tar.bz2
rails-01f06fc7f4dda52035d5a2273d402d8555a897a5.zip
Don't let empty Tempfiles come through as uploaded files [#1785 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
-rw-r--r--actionpack/lib/action_controller/url_encoded_pair_parser.rb2
-rw-r--r--actionpack/test/controller/request/multipart_params_parsing_test.rb7
-rw-r--r--actionpack/test/fixtures/multipart/empty9
3 files changed, 17 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/url_encoded_pair_parser.rb b/actionpack/lib/action_controller/url_encoded_pair_parser.rb
index b63dca987d..93ab2255da 100644
--- a/actionpack/lib/action_controller/url_encoded_pair_parser.rb
+++ b/actionpack/lib/action_controller/url_encoded_pair_parser.rb
@@ -46,7 +46,7 @@ module ActionController
when Array
value.map { |v| get_typed_value(v) }
when Hash
- if value.has_key?(:tempfile)
+ if value.has_key?(:tempfile) && value[:tempfile].size > 0
upload = value[:tempfile]
upload.extend(UploadedFile)
upload.original_path = value[:filename]
diff --git a/actionpack/test/controller/request/multipart_params_parsing_test.rb b/actionpack/test/controller/request/multipart_params_parsing_test.rb
index d7ade40f71..18235845f3 100644
--- a/actionpack/test/controller/request/multipart_params_parsing_test.rb
+++ b/actionpack/test/controller/request/multipart_params_parsing_test.rb
@@ -101,6 +101,13 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest
assert_equal 19756, files.size
end
+ test "skips empty upload field" do
+ params = parse_multipart('empty')
+ assert_equal %w(files submit-name), params.keys.sort
+ assert_equal 'Larry', params['submit-name']
+ assert_equal nil, params['file']
+ end
+
test "uploads and reads binary file" do
with_test_routing do
fixture = FIXTURE_PATH + "/mona_lisa.jpg"
diff --git a/actionpack/test/fixtures/multipart/empty b/actionpack/test/fixtures/multipart/empty
new file mode 100644
index 0000000000..d66f4730f1
--- /dev/null
+++ b/actionpack/test/fixtures/multipart/empty
@@ -0,0 +1,9 @@
+--AaB03x
+Content-Disposition: form-data; name="submit-name"
+
+Larry
+--AaB03x
+Content-Disposition: form-data; name="files"; filename=""
+
+
+--AaB03x--