diff options
author | Joshua Peek <josh@joshpeek.com> | 2009-01-20 20:34:35 -0600 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-01-20 20:34:35 -0600 |
commit | a8ad6568f9fe21668df9b6b631c0cd9783cb5ab3 (patch) | |
tree | e7171c5cd9931fbfc3b48dfc2be9c6e58eae1bb5 | |
parent | 7e4d13d357b1e8bdf42e80359de0e480ec9f5008 (diff) | |
download | rails-a8ad6568f9fe21668df9b6b631c0cd9783cb5ab3.tar.gz rails-a8ad6568f9fe21668df9b6b631c0cd9783cb5ab3.tar.bz2 rails-a8ad6568f9fe21668df9b6b631c0cd9783cb5ab3.zip |
Allow empty files to be uploaded
4 files changed, 22 insertions, 4 deletions
diff --git a/actionpack/lib/action_controller/url_encoded_pair_parser.rb b/actionpack/lib/action_controller/url_encoded_pair_parser.rb index 93ab2255da..57594c4259 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) && value[:tempfile].size > 0 + if value.has_key?(:tempfile) && value[:filename].any? 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 18235845f3..054519d0d2 100644 --- a/actionpack/test/controller/request/multipart_params_parsing_test.rb +++ b/actionpack/test/controller/request/multipart_params_parsing_test.rb @@ -101,11 +101,19 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest assert_equal 19756, files.size end - test "skips empty upload field" do + test "does not create tempfile if no file has been selected" do + params = parse_multipart('none') + assert_equal %w(files submit-name), params.keys.sort + assert_equal 'Larry', params['submit-name'] + assert_equal nil, params['files'] + end + + test "parses empty upload file" 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'] + assert params['files'] + assert_equal "", params['files'].read end test "uploads and reads binary file" do diff --git a/actionpack/test/fixtures/multipart/empty b/actionpack/test/fixtures/multipart/empty index d66f4730f1..f0f79835c9 100644 --- a/actionpack/test/fixtures/multipart/empty +++ b/actionpack/test/fixtures/multipart/empty @@ -3,7 +3,8 @@ Content-Disposition: form-data; name="submit-name" Larry
--AaB03x
-Content-Disposition: form-data; name="files"; filename=""
+Content-Disposition: form-data; name="files"; filename="file1.txt"
+Content-Type: text/plain
--AaB03x--
diff --git a/actionpack/test/fixtures/multipart/none b/actionpack/test/fixtures/multipart/none new file mode 100644 index 0000000000..d66f4730f1 --- /dev/null +++ b/actionpack/test/fixtures/multipart/none @@ -0,0 +1,9 @@ +--AaB03x
+Content-Disposition: form-data; name="submit-name"
+
+Larry
+--AaB03x
+Content-Disposition: form-data; name="files"; filename=""
+
+
+--AaB03x--
|