Permalink
Browse files

Don't let empty Tempfiles come through as uploaded files [#1785 state…

…:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information...
1 parent c090e5e commit 01f06fc7f4dda52035d5a2273d402d8555a897a5 @mislav mislav committed with josh Jan 20, 2009
@@ -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)
+ if value.has_key?(:tempfile) && value[:tempfile].size > 0
upload = value[:tempfile]
upload.extend(UploadedFile)
upload.original_path = value[:filename]
@@ -101,6 +101,13 @@ def teardown
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"
@@ -0,0 +1,9 @@
+--AaB03x
+Content-Disposition: form-data; name="submit-name"
+
+Larry
+--AaB03x
+Content-Disposition: form-data; name="files"; filename=""
+
+
+--AaB03x--

1 comment on commit 01f06fc

Owner
fxn commented on 01f06fc Jan 20, 2009

I think this test is unnecessarily weak. Please see comments in http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1785

Please sign in to comment.