Skip to content

Commit

Permalink
Merge pull request #3813 from crazyserver/MOBILE-4407
Browse files Browse the repository at this point in the history
MOBILE-4407 url: Use Url parsing to determine last file
  • Loading branch information
NoelDeMartin authored Oct 10, 2023
2 parents 225caa0 + 245e707 commit 78aacf8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
16 changes: 7 additions & 9 deletions src/core/directives/external-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges, O
}

/**
* View has been initialized
* @inheritdoc
*/
ngAfterViewInit(): void {
this.checkAndHandleExternalContent();
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
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 78aacf8

Please sign in to comment.