Skip to content

Commit 5e703b6

Browse files
committed
fix(utils): simplified 'getFileExtension()' to pass all test cases
1 parent a14e493 commit 5e703b6

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/js/utils/url.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,12 @@ export const getAbsoluteURL = function(url) {
4747
*/
4848
export const getFileExtension = function(path) {
4949
if (typeof path === 'string') {
50-
const splitPathRe = /^(\/?)([\s\S]*?)((?:\.{1,2}|[^\/]+?)(\.*([^\.\/\?]+)))(?:[\/]*|[\?].*)$/;
51-
const pathParts = splitPathRe.exec(path);
50+
const cleanPath = path.split('?')[0];
5251

53-
if (pathParts) {
54-
return pathParts.pop().toLowerCase();
55-
}
56-
}
52+
const match = cleanPath.match(/\.([^.\/]+)$/);
5753

54+
return match ? match[1].toLowerCase() : '';
55+
}
5856
return '';
5957
};
6058

0 commit comments

Comments
 (0)