Skip to content

Commit

Permalink
MOBILE-4407 url: Use Url parsing to determine last file
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyserver committed Oct 10, 2023
1 parent 225caa0 commit 156d34d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/core/services/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,13 @@ export class CoreUrlUtilsProvider {
* @returns Last file without params.
*/
getLastFileWithoutParams(url: string): string {
let filename = url.substring(url.lastIndexOf('/') + 1);
if (filename.indexOf('?') != -1) {
filename = filename.substring(0, filename.indexOf('?'));
const parsedUrl = CoreUrl.parse(url);
if (!parsedUrl) {
return '';
}
const path = parsedUrl.path ?? '';

return filename;
return path.split('/').pop() ?? '';
}

/**
Expand All @@ -346,6 +347,7 @@ export class CoreUrlUtilsProvider {
*
* @param url URL to treat.
* @returns Protocol, undefined if no protocol found.
* @todo Use CoreUrl.parse
*/
getUrlProtocol(url: string): string | void {
if (!url) {
Expand Down Expand Up @@ -381,6 +383,7 @@ export class CoreUrlUtilsProvider {
*
* @param url URL to treat.
* @returns Username. Undefined if no username found.
* @todo Use CoreUrl.parse
*/
getUsernameFromUrl(url: string): string | undefined {
if (url.indexOf('@') > -1) {
Expand Down Expand Up @@ -430,6 +433,7 @@ export class CoreUrlUtilsProvider {
*
* @param url The url to test.
* @returns Whether the url uses http or https protocol.
* @todo Use CoreUrl.parse
*/
isHttpURL(url: string): boolean {
return /^https?:\/\/.+/i.test(url);
Expand Down

0 comments on commit 156d34d

Please sign in to comment.