fix(upload): should work correctly when url of file is null (#30215)

* fix(upload): should work correctly when url of file is null

* fix: lint
This commit is contained in:
Kermit 2021-04-20 09:58:02 +08:00 committed by GitHub
parent 7975c33f50
commit 1f1aa86441
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -6,7 +6,7 @@ import produce from 'immer';
import { cloneDeep } from 'lodash';
import Upload from '..';
import Form from '../../form';
import { getFileItem, removeFileItem } from '../utils';
import { getFileItem, removeFileItem, isImageUrl } from '../utils';
import { setup, teardown } from './mock';
import { resetWarned } from '../../_util/devWarning';
import mountTest from '../../../tests/shared/mountTest';
@ -367,6 +367,13 @@ describe('Upload', () => {
const targetItem = removeFileItem(file, fileList);
expect(targetItem).toBe(null);
});
it('isImageUrl should work correctly when file.url is null', () => {
const file = {
url: null,
};
expect(isImageUrl(file)).toBe(true);
});
});
it('should support linkProps as object', () => {

View File

@ -54,7 +54,7 @@ export const isImageUrl = (file: UploadFile): boolean => {
if (file.type && !file.thumbUrl) {
return isImageFileType(file.type);
}
const url: string = (file.thumbUrl || file.url) as string;
const url: string = (file.thumbUrl || file.url || '') as string;
const extension = extname(url);
if (
/^data:image\//.test(url) ||