diff --git a/src/utility/upload.ts b/src/utility/upload.ts index 3165aa17..35194078 100644 --- a/src/utility/upload.ts +++ b/src/utility/upload.ts @@ -61,13 +61,18 @@ function isAcceptableFile(file: File, accept: string) { const wildcards = ['audio/*', 'image/*', 'video/*'] - return accept.split(',').some(acceptToken => { - if (acceptToken.startsWith('.')) { - // tokens starting with a dot represent a file extension - return file.name.endsWith(acceptToken) - } else if (wildcards.includes(acceptToken)) { - return file.type.startsWith(acceptToken.substr(0, acceptToken.length - 1)) - } - return file.type === acceptToken - }) + return accept + .split(',') + .map(acceptToken => acceptToken.trim()) + .some(acceptToken => { + if (acceptToken.startsWith('.')) { + // tokens starting with a dot represent a file extension + return file.name.endsWith(acceptToken) + } else if (wildcards.includes(acceptToken)) { + return file.type.startsWith( + acceptToken.substr(0, acceptToken.length - 1), + ) + } + return file.type === acceptToken + }) } diff --git a/tests/utility/upload.ts b/tests/utility/upload.ts index ad887347..e880396c 100644 --- a/tests/utility/upload.ts +++ b/tests/utility/upload.ts @@ -155,6 +155,7 @@ test.each([ [true, '.png', 1], [true, 'text/csv', 1], [true, '', 4], + [true, '.png, .jpg', 3], [false, 'video/*', 4], ])( 'filter according to accept attribute applyAccept=%s, acceptAttribute=%s',