FIX: empty uploads and blank filenames caused errors during validation

This commit is contained in:
Gerhard Schlager 2017-12-13 21:51:09 +01:00
parent 76e8a28420
commit f525d83b53
2 changed files with 9 additions and 2 deletions

View File

@ -21,9 +21,9 @@ class UploadCreator
# - for_private_message (boolean)
# - pasted (boolean)
def initialize(file, filename, opts = {})
@upload = Upload.new
@file = file
@filename = filename
@filename = filename || ''
@upload = Upload.new(original_filename: filename, filesize: 0)
@opts = opts
end

View File

@ -51,6 +51,13 @@ describe Upload do
expect(created_upload.extension).to eq("png")
end
it "should create an invalid upload when the filename is blank" do
SiteSetting.authorized_extensions = "*"
created_upload = UploadCreator.new(image, nil).create_for(user_id)
expect(created_upload.valid?).to eq(false)
end
context ".get_from_url" do
let(:url) { "/uploads/default/original/3X/1/0/10f73034616a796dfd70177dc54b6def44c4ba6f.png" }
let(:upload) { Fabricate(:upload, url: url) }