Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(comp:upload): accept does not ignore case #1544

Merged
merged 1 commit into from
Apr 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions packages/components/upload/src/util/fileHandle.ts
Original file line number Diff line number Diff line change
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
Loading