1
0
Fork 0
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:
Joshua Peek 2009-01-20 20:34:35 -06:00
parent 7e4d13d357
commit a8ad6568f9
4 changed files with 22 additions and 4 deletions

View file

@ -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]

View file

@ -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

View file

@ -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 file

@ -0,0 +1,9 @@
--AaB03x
Content-Disposition: form-data; name="submit-name"
Larry
--AaB03x
Content-Disposition: form-data; name="files"; filename=""
--AaB03x--