Skip to content

Commit d32f351

Browse files
flore2003madoBaker
authored andcommitted
fix(image-loader): URLs with query params lead to broken filenames (#196)
1 parent d4132f1 commit d32f351

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/providers/image-loader.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ export class ImageLoader {
684684
return (
685685
this.hashString(url).toString() +
686686
(this.config.fileNameCachedWithExtension
687-
? this.getExtensionFromFileName(url)
687+
? this.getExtensionFromUrl(url)
688688
: '')
689689
);
690690
}
@@ -711,15 +711,15 @@ export class ImageLoader {
711711
}
712712

713713
/**
714-
* extract extension from filename or url
714+
* Extract extension from filename or url
715715
*
716-
* @param {string} filename
716+
* @param {string} url
717717
* @returns {string}
718718
*/
719-
private getExtensionFromFileName(filename: string): string {
719+
private getExtensionFromUrl(url: string): string {
720+
const urlWitoutParams = url.split(/\#|\?/)[0];
720721
return (
721-
// tslint:disable-next-line
722-
filename.substr((~-filename.lastIndexOf('.') >>> 0) + 1) ||
722+
urlWitoutParams.substr((~-urlWitoutParams.lastIndexOf('.') >>> 0) + 1) ||
723723
this.config.fallbackFileNameCachedExtension
724724
);
725725
}

0 commit comments

Comments
 (0)