Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow empty files to be uploaded

  • Loading branch information...
commit a8ad6568f9fe21668df9b6b631c0cd9783cb5ab3 1 parent 7e4d13d
@josh josh authored
View
2  actionpack/lib/action_controller/url_encoded_pair_parser.rb
@@ -46,7 +46,7 @@ def get_typed_value(value)
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]
View
12 actionpack/test/controller/request/multipart_params_parsing_test.rb
@@ -101,11 +101,19 @@ def teardown
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
View
3  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--
View
9 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--
Please sign in to comment.
Something went wrong with that request. Please try again.