don't raise an error if an uploaded file has no original filename
Browsers tend to send a filename, but some API clients don't. fixes CNVS-4233 test plan: do a multipart file upload to an api endpoint, such as a sis api, and leave out the filename=/original/filename component of the parameter. the upload should still be accepted and no error raised. Change-Id: I9be8d425693cfb9d8d44644e57358f5dc9cee4c1 Reviewed-on: https://gerrit.instructure.com/18114 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Cody Cutrer <cody@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com> QA-Review: Clare Hetherington <clare@instructure.com>
This commit is contained in:
parent
394e915a36
commit
54f43dd81d
|
@ -98,7 +98,7 @@ else
|
|||
o.force_encoding(Encoding::UTF_8)
|
||||
raise ActionController::InvalidByteSequenceErrorFromParams unless o.valid_encoding?
|
||||
end
|
||||
if o.respond_to?(:original_filename)
|
||||
if o.respond_to?(:original_filename) && o.original_filename
|
||||
o.original_filename.force_encoding(Encoding::UTF_8)
|
||||
raise ActionController::InvalidByteSequenceErrorFromParams unless o.original_filename.valid_encoding?
|
||||
end
|
||||
|
|
|
@ -20,4 +20,16 @@ describe 'ruby_version_compat' do
|
|||
output.should == ['', '']
|
||||
end
|
||||
end
|
||||
|
||||
describe "force_utf8_params" do
|
||||
it "should allow null filenames through" do
|
||||
testfile = ActionController::TestUploadedFile.new(File.join(File.dirname(__FILE__), "/../fixtures/scribd_docs/txt.txt"), "text/plain", true)
|
||||
testfile.instance_variable_set(:@original_filename, nil)
|
||||
controller = ApplicationController.new
|
||||
controller.stubs(:params).returns({ :upload => { :file1 => testfile } })
|
||||
controller.stubs(:request).returns(mock(:path => "/upload"))
|
||||
expect { controller.force_utf8_params() }.to_not raise_error
|
||||
testfile.original_filename.should be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue