cpradio
(cpradio)
September 16, 2016, 5:22pm
2
I maybe wrong, but it may be related to this
render nothing: true, status: status
end
def upload_backup_chunk
filename = params.fetch(:resumableFilename)
total_size = params.fetch(:resumableTotalSize).to_i
return render status: 415, text: I18n.t("backup.backup_file_should_be_tar_gz") unless /\.(tar\.gz|t?gz)$/i =~ filename
return render status: 415, text: I18n.t("backup.not_enough_space_on_disk") unless has_enough_space_on_disk?(total_size)
return render status: 415, text: I18n.t("backup.invalid_filename") unless !!(/^[a-zA-Z0-9\.-_]+$/ =~ filename)
file = params.fetch(:file)
identifier = params.fetch(:resumableIdentifier)
chunk_number = params.fetch(:resumableChunkNumber).to_i
chunk_size = params.fetch(:resumableChunkSize).to_i
current_chunk_size = params.fetch(:resumableCurrentChunkSize).to_i
# path to chunk file
chunk = Backup.chunk_path(identifier, filename, chunk_number)
# upload chunk
From this commit:
https://github.com/discourse/discourse/commit/512922d7767c84615b8b77089e34ede244a88c7f
And the fact that - may need to be escaped like . is. Alternatively, if you list - at the very end, it should work too but being between two characters, it thinks it is trying to define a range.
So either
/^[a-zA-Z0-9\.\-_]+$/ or /^[a-zA-Z0-9\._-]+$/ should work
Thoughts @tgxworld ?
Also, I think it would be better to make the test, use ‘test_Site-0123456789.tar.gz’ so that it utilizes all of the characters you are permitting.
expect(response.status).to eq(415)
expect(response.body).to eq(I18n.t('backup.invalid_filename'))
end
end
end
describe "when filename is valid" do
it "should upload the file successfully" do
xhr :post, :upload_backup_chunk,
resumableFilename: 'test.tar.gz',
resumableTotalSize: '1',
resumableIdentifier: 'test',
resumableChunkNumber: '1',
resumableChunkSize: '1',
resumableCurrentChunkSize: '1',
file: fixture_file_upload(Tempfile.new)
expect(response.status).to eq(200)
expect(response.body).to eq("")
end
3 Likes