Skip to content

Commit

Permalink
fix(comp:upload): accept does not ignore case (#1544)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzaijiang committed Apr 29, 2023
1 parent 7448e38 commit b7e9b89
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions packages/components/upload/src/util/fileHandle.ts
Expand Up @@ -47,22 +47,22 @@ export function getFilesAcceptAllow(filesSelected: File[], accept?: string[]): F
if (!accept || accept.length === 0) {
return filesSelected
}
return filesSelected.filter(file => {
const extension = file.name.indexOf('.') > -1 ? `.${file.name.split('.').pop()}` : ''
const baseType = file.type.replace(/\/.*$/, '')
return accept.some(type => {
if (type.startsWith('.')) {
return extension === type
}
if (/\/\*$/.test(type)) {
return baseType === type.replace(/\/\*$/, '')
}
if (/^[^/]+\/[^/]+$/.test(type)) {
return file.type === type
}
return false
})
})
const isMatch = (file: File, type: string) => {
const ext = `.${file.name.split('.').pop()}`.toLowerCase()
const baseType = file.type.replace(/\/.*$/, '').toLowerCase()
const _type = type.toLowerCase()
if (_type.startsWith('.')) {
return ext === _type
}
if (/\/\*$/.test(_type)) {
return baseType === _type.replace(/\/\*$/, '')
}
if (/^[^/]+\/[^/]+$/.test(_type)) {
return file.type.toLowerCase() === _type
}
return false
}
return filesSelected.filter(file => accept.some(type => isMatch(file, type)))
}

export function getFilesCountAllow(filesSelected: File[], curFilesCount: number, maxCount?: number): File[] {
Expand Down

0 comments on commit b7e9b89

Please sign in to comment.