Skip to content

Commit

Permalink
fix(utilities): extractFileNameFromURL can't parse on available query…
Browse files Browse the repository at this point in the history
… params
  • Loading branch information
julianpoemp committed Jan 14, 2025
1 parent 107c0b1 commit 4587ba3
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions libs/utilities/src/lib/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,19 @@ export function extractFileNameFromURL(url: string): {
name: string;
extension: string;
} {
const matches = /\/([^/?]*)(\.[^/?]+)(?:\?|$)/g.exec(url);
if (url.includes('?')) {
url = url.split('?')[0];
}
let matches = /\/([^/?]*)$/g.exec(url);

if (matches === null || matches.length < 2) {
throw new Error("Can't read file from URL 1.");
}

matches = /([^.]+)(\.[^.]+)?$/g.exec(matches[1]);

if (matches === null || matches.length < 3) {
throw new Error("Can't read file from URL.");
if (matches === null || matches.length < 2) {
throw new Error("Can't read file from URL 2.");
}

return {
Expand Down

0 comments on commit 4587ba3

Please sign in to comment.