mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-12-02 05:04:13 +01:00
Set text/plain content type for plain-text upload error responses
This commit is contained in:
1 parent
0afb582f09
commit
47bdd3d2dc
2 files changed
+23
No files matched your search
@@ -63,6 +63,7 @@ class MiscController {
|
||||
if (error instanceof uploadPath.UploadError) {
|
||||
Logger.warn(`[MiscController] User "${req.user.username}" upload failed (${error.statusCode}): ${error.message}`)
|
||||
if (error.body) return res.status(error.statusCode).json(error.body)
|
||||
res.type('text/plain')
|
||||
return res.status(error.statusCode).send(error.message)
|
||||
}
|
||||
return res.sendStatus(500)
|
||||
|
||||
@@ -51,7 +51,12 @@ describe('upload path collisions', () => {
|
||||
function mockRes() {
|
||||
return {
|
||||
statusCode: 200,
|
||||
contentType: undefined,
|
||||
body: undefined,
|
||||
type(contentType) {
|
||||
this.contentType = contentType
|
||||
return this
|
||||
},
|
||||
status(code) {
|
||||
this.statusCode = code
|
||||
return this
|
||||
@@ -534,6 +539,23 @@ describe('upload path collisions', () => {
|
||||
expect(await pathExists(Path.join(folder.path, 'NewAuthor'))).to.equal(false)
|
||||
})
|
||||
|
||||
it('refuses a file name that sanitizes to empty as plain text', async () => {
|
||||
const res = mockRes()
|
||||
await MiscController.handleUpload(
|
||||
uploadRequest({
|
||||
files: {
|
||||
0: fakeUploadFile('...', 'new-audio')
|
||||
}
|
||||
}),
|
||||
res
|
||||
)
|
||||
|
||||
expect(res.statusCode).to.equal(400)
|
||||
expect(res.contentType).to.equal('text/plain')
|
||||
expect(res.body).to.equal('Invalid file name')
|
||||
expect(await pathExists(Path.join(folder.path, 'Author A'))).to.equal(false)
|
||||
})
|
||||
|
||||
it('drops an author name that sanitizes to empty', async () => {
|
||||
const res = mockRes()
|
||||
await MiscController.handleUpload(
|
||||
|
||||
Reference in new issue
Block a user