MOBILE-4407 url: Use Url parsing to determine last file

main
Pau Ferrer Ocaña 2023-10-10 15:50:30 +02:00
parent 225caa04b1
commit 245e7071a9
2 changed files with 15 additions and 13 deletions

View File

@ -81,7 +81,7 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges, O
}
/**
* View has been initialized
* @inheritdoc
*/
ngAfterViewInit(): void {
this.checkAndHandleExternalContent();
@ -90,9 +90,7 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges, O
}
/**
* Listen to changes.
*
* * @param {{[name: string]: SimpleChange}} changes Changes.
* @inheritdoc
*/
ngOnChanges(changes: { [name: string]: SimpleChange }): void {
if (changes && this.initialized) {
@ -134,23 +132,23 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges, O
protected async checkAndHandleExternalContent(): Promise<void> {
const siteId = this.siteId || CoreSites.getRequiredCurrentSite().getId();
const tagName = this.element.tagName.toUpperCase();
let targetAttr;
let url;
let targetAttr: string;
let url: string;
// Always handle inline styles (if any).
this.handleInlineStyles(siteId);
if (tagName === 'A' || tagName == 'IMAGE') {
targetAttr = 'href';
url = this.href;
url = this.href ?? '';
} else if (tagName === 'IMG') {
targetAttr = 'src';
url = this.src;
url = this.src ?? '';
} else if (tagName === 'AUDIO' || tagName === 'VIDEO' || tagName === 'SOURCE' || tagName === 'TRACK') {
targetAttr = 'src';
url = this.targetSrc || this.src;
url = (this.targetSrc || this.src) ?? '';
if (tagName === 'VIDEO') {
if (this.poster) {

View File

@ -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() ?? '';
}
/**
@ -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) {
@ -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) {
@ -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);