Skip to content

Commit

Permalink
Merge pull request #473 from digital-land/450-bug-error-reviewing-url…
Browse files Browse the repository at this point in the history
…-on-check

Allow files with undefined `content-length` headers
  • Loading branch information
DilwoarH authored Sep 27, 2024
2 parents 957fbab + d9e98c7 commit f182561
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/controllers/submitUrlController.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,14 @@ class SubmitUrlController extends UploadController {
*/
static urlResponseIsNotTooLarge (response) {
const contentLength = (response?.headers ?? {})['content-length']

try {
// if the content length header is not provided, return true
if (!contentLength) {
console.warn(`urlResponseIsNotTooLarge(): response.config.url=${response.config.url}`, { type: types.App, errorMessage: 'Content-Length header not provided' })
return true
}

return contentLength <= config.validations.maxFileSize
} catch (err) {
console.warn('urlResponseIsNotTooLarge()', { type: types.App, errorMessage: err.message, errorStack: err.stack, contentLength })
Expand Down
4 changes: 4 additions & 0 deletions test/unit/submitUrlController.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ describe('SubmitUrlController', async () => {
it('should return false for URLs with a response larger than the max file size', async () => {
expect(SubmitUrlController.urlResponseIsNotTooLarge({ headers: { 'content-length': config.validations.maxFileSize + 21 } })).toBe(false)
})

it('should return true for URLs without a content length header', async () => {
expect(SubmitUrlController.urlResponseIsNotTooLarge({ headers: { } })).toBe(true)
})
})

describe('urlExists', () => {
Expand Down

0 comments on commit f182561

Please sign in to comment.