MOBILE-3947 core: Fix extension detection in guessExtensionFromUrl

main
Dani Palou 2024-01-12 12:20:54 +01:00
parent dfd7f89491
commit 03eb3e7dcb
1 changed files with 4 additions and 9 deletions

View File

@ -312,17 +312,12 @@ export class CoreMimetypeUtilsProvider {
* @returns The lowercased extension without the dot, or undefined.
*/
guessExtensionFromUrl(fileUrl: string): string | undefined {
const split = CoreUrl.removeUrlAnchor(fileUrl).split('.');
const parsed = CoreUrl.parse(fileUrl);
const split = parsed?.path?.split('.');
let extension: string | undefined;
if (split.length > 1) {
let candidate = split[split.length - 1].toLowerCase();
// Remove params if any.
const position = candidate.indexOf('?');
if (position > -1) {
candidate = candidate.substring(0, position);
}
if (split && split.length > 1) {
const candidate = split[split.length - 1].toLowerCase();
if (EXTENSION_REGEX.test(candidate)) {
extension = candidate;
}