A platform for community discussion. Free, open, simple.
FIX: Missing extensions for non-image uploads due to https://github.com/tgxworld/discourse/commit/2b5723938920647c45f7fc526e1edd19e8fad09e.
Guo Xiang Tand10c9d7d758f
diff --git a/lib/upload_creator.rb b/lib/upload_creator.rbindex a063bdb361f..10b5902a001 100644--- a/lib/upload_creator.rb+++ b/lib/upload_creator.rb@@ -79,7 +79,7 @@ class UploadCreator@upload.sha1 = sha1@upload.url = ""@upload.origin = @opts[:origin][0...1000] if @opts[:origin]- @upload.extension = image_type+ @upload.extension = image_type || File.extname(@filename)[1..10]if FileHelper.is_image?(@filename)@upload.width, @upload.height = ImageSizer.resize(*@image_info.size)diff --git a/spec/requests/uploads_controller_spec.rb b/spec/requests/uploads_controller_spec.rbindex 63475547710..62ba2562435 100644--- a/spec/requests/uploads_controller_spec.rb+++ b/spec/requests/uploads_controller_spec.rb@@ -164,7 +164,29 @@ describe UploadsController doexpect(message).to contain_exactly(I18n.t("upload.images.size_not_found"))end- describe 'when filename has the wrong extension' do+ describe 'when upload is not an image' do+ before do+ SiteSetting.authorized_extensions = 'txt'+ end++ let(:file) do+ Rack::Test::UploadedFile.new(file_from_fixtures("utf-8.txt", "encodings"))+ end++ it 'should store the upload with the right extension' do+ expect do+ post "/uploads.json", params: { file: file, type: "composer" }+ end.to change { Upload.count }.by(1)++ upload = Upload.last++ expect(upload.extension).to eq('txt')+ expect(File.extname(upload.url)).to eq('.txt')+ expect(upload.original_filename).to eq('utf-8.txt')+ end+ end++ describe 'when image has the wrong extension' dolet(:file) doRack::Test::UploadedFile.new(file_from_fixtures("png_as.jpg"))end