Skip to content

Commit

Permalink
MOBILE-3947 core: Fix extension detection in guessExtensionFromUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
dpalou committed Jan 12, 2024
1 parent dfd7f89 commit 03eb3e7
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/core/services/utils/mimetype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 03eb3e7

Please sign in to comment.