mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +08:00
FIX: empty uploads and blank filenames caused errors during validation
This commit is contained in:
@ -21,9 +21,9 @@ class UploadCreator
|
|||||||
# - for_private_message (boolean)
|
# - for_private_message (boolean)
|
||||||
# - pasted (boolean)
|
# - pasted (boolean)
|
||||||
def initialize(file, filename, opts = {})
|
def initialize(file, filename, opts = {})
|
||||||
@upload = Upload.new
|
|
||||||
@file = file
|
@file = file
|
||||||
@filename = filename
|
@filename = filename || ''
|
||||||
|
@upload = Upload.new(original_filename: filename, filesize: 0)
|
||||||
@opts = opts
|
@opts = opts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -51,6 +51,13 @@ describe Upload do
|
|||||||
expect(created_upload.extension).to eq("png")
|
expect(created_upload.extension).to eq("png")
|
||||||
end
|
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
|
context ".get_from_url" do
|
||||||
let(:url) { "/uploads/default/original/3X/1/0/10f73034616a796dfd70177dc54b6def44c4ba6f.png" }
|
let(:url) { "/uploads/default/original/3X/1/0/10f73034616a796dfd70177dc54b6def44c4ba6f.png" }
|
||||||
let(:upload) { Fabricate(:upload, url: url) }
|
let(:upload) { Fabricate(:upload, url: url) }
|
||||||
|
Reference in New Issue
Block a user