Skip to content
Snippets Groups Projects
Commit 72590e02 authored by Christian Bager Bach Houmann's avatar Christian Bager Bach Houmann
Browse files

fix: url extension detection match by regular expression for accuracy

parent 3b511fa5
No related branches found
No related tags found
No related merge requests found
export default function getUrlExtension(url: string): string {
const extension = url.split('.').pop()?.split(/[#?]/).pop();
const regexp = new RegExp(/\.([0-9a-z]+)(?:[?#]|$)/i);
const match = regexp.exec(url);
if (extension?.contains(url)) {
// Extraction failed
return "";
if (!match) {
return '';
}
return extension ?? "";
const [, extension] = match;
return extension;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment