Skip to content

Commit 68b1b5a

Browse files
committed
fix(utils): properly retrieve file extensions from URLs that contain query parameters
1 parent f0717e8 commit 68b1b5a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

packages/uikit-utils/src/shared/regex.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,16 @@ export const getFileType = (extOrType: string) => {
6868
return 'file';
6969
};
7070
export function getFileExtension(filePath: string) {
71-
const idx = filePath.lastIndexOf('.');
71+
const pathWithoutParams = filePath.split('?')[0];
72+
73+
const idx = pathWithoutParams.lastIndexOf('.');
7274
if (idx === -1) return '';
73-
return filePath.slice(idx - filePath.length).toLowerCase();
75+
76+
const result = pathWithoutParams.slice(idx - pathWithoutParams.length).toLowerCase();
77+
if (result === '.') return '';
78+
else return result;
7479
}
80+
7581
export function normalizeFileName(fileName: string, extension: string) {
7682
if (fileName.indexOf(extension) > -1) {
7783
return fileName;

0 commit comments

Comments
 (0)