mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 22:51:06 +08:00
correct regression around file renaming
This commit is contained in:
@ -78,11 +78,20 @@ class UploadCreator
|
|||||||
|
|
||||||
fixed_original_filename = nil
|
fixed_original_filename = nil
|
||||||
if is_image
|
if is_image
|
||||||
|
|
||||||
|
current_extension = File.extname(@filename).downcase.sub("jpeg", "jpg")
|
||||||
|
expected_extension = ".#{image_type}".downcase.sub("jpeg", "jpg")
|
||||||
|
|
||||||
# we have to correct original filename here, no choice
|
# we have to correct original filename here, no choice
|
||||||
# otherwise validation will fail and we can not save
|
# otherwise validation will fail and we can not save
|
||||||
# TODO decide if we only run the validation on the extension
|
# TODO decide if we only run the validation on the extension
|
||||||
if File.extname(@filename) != ".#{image_type}"
|
if current_extension != expected_extension
|
||||||
fixed_original_filename = "#{@filename}_fixed.#{image_type}"
|
basename = File.basename(@filename, current_extension)
|
||||||
|
|
||||||
|
if basename.length == 0
|
||||||
|
basename = "image"
|
||||||
|
end
|
||||||
|
fixed_original_filename = "#{basename}#{expected_extension}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ RSpec.describe UploadCreator do
|
|||||||
|
|
||||||
expect(upload.extension).to eq('png')
|
expect(upload.extension).to eq('png')
|
||||||
expect(File.extname(upload.url)).to eq('.png')
|
expect(File.extname(upload.url)).to eq('.png')
|
||||||
expect(upload.original_filename).to eq('png_as.bin_fixed.png')
|
expect(upload.original_filename).to eq('png_as.png')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ RSpec.describe UploadCreator do
|
|||||||
|
|
||||||
expect(upload.extension).to eq('jpeg')
|
expect(upload.extension).to eq('jpeg')
|
||||||
expect(File.extname(upload.url)).to eq('.jpeg')
|
expect(File.extname(upload.url)).to eq('.jpeg')
|
||||||
expect(upload.original_filename).to eq('logo.png_fixed.jpeg')
|
expect(upload.original_filename).to eq('logo.jpg')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -212,7 +212,7 @@ describe UploadsController do
|
|||||||
|
|
||||||
get "/uploads/#{site}/#{upload.sha1}.json"
|
get "/uploads/#{site}/#{upload.sha1}.json"
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
expect(response.headers["Content-Disposition"]).to eq("attachment; filename=\"image_no_extension_fixed.png\"")
|
expect(response.headers["Content-Disposition"]).to eq("attachment; filename=\"image_no_extension.png\"")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "handles file without extension" do
|
it "handles file without extension" do
|
||||||
|
Reference in New Issue
Block a user