mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Allow empty files to be uploaded
This commit is contained in:
parent
7e4d13d357
commit
a8ad6568f9
4 changed files with 22 additions and 4 deletions
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
3
actionpack/test/fixtures/multipart/empty
vendored
3
actionpack/test/fixtures/multipart/empty
vendored
|
@ -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--
|
||||
|
|
9
actionpack/test/fixtures/multipart/none
vendored
Normal file
9
actionpack/test/fixtures/multipart/none
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
--AaB03x
|
||||
Content-Disposition: form-data; name="submit-name"
|
||||
|
||||
Larry
|
||||
--AaB03x
|
||||
Content-Disposition: form-data; name="files"; filename=""
|
||||
|
||||
|
||||
--AaB03x--
|
Loading…
Reference in a new issue