From f8d3c023ccb92dfef28059d6633907d3cdc81033 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 4 May 2023 11:59:01 +0200 Subject: [PATCH] MOBILE-4303 iframe: Fix auto-login applied in H5P local URLs --- src/core/components/iframe/iframe.ts | 24 +++++++++++++++--------- src/core/services/utils/url.ts | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/core/components/iframe/iframe.ts b/src/core/components/iframe/iframe.ts index 9729eb8a9..bcccf96ac 100644 --- a/src/core/components/iframe/iframe.ts +++ b/src/core/components/iframe/iframe.ts @@ -156,8 +156,14 @@ export class CoreIframeComponent implements OnChanges, OnDestroy { * Detect changes on input properties. */ async ngOnChanges(changes: {[name: string]: SimpleChange }): Promise { - if (changes.src) { - let url = CoreUrlUtils.getYoutubeEmbedUrl(changes.src.currentValue) || changes.src.currentValue; + if (!changes.src) { + return; + } + + let url = changes.src.currentValue; + + if (!CoreUrlUtils.isLocalFileUrl(url)) { + url = CoreUrlUtils.getYoutubeEmbedUrl(changes.src.currentValue) || changes.src.currentValue; this.displayHelp = CoreIframeUtils.shouldDisplayHelpForUrl(url); const currentSite = CoreSites.getCurrentSite(); @@ -173,14 +179,14 @@ export class CoreIframeComponent implements OnChanges, OnDestroy { } await CoreIframeUtils.fixIframeCookies(url); - - this.safeUrl = DomSanitizer.bypassSecurityTrustResourceUrl(CoreFile.convertFileSrc(url)); - - // Now that the URL has been set, initialize the iframe. Wait for the iframe to the added to the DOM. - setTimeout(() => { - this.init(); - }); } + + this.safeUrl = DomSanitizer.bypassSecurityTrustResourceUrl(CoreFile.convertFileSrc(url)); + + // Now that the URL has been set, initialize the iframe. Wait for the iframe to the added to the DOM. + setTimeout(() => { + this.init(); + }); } /** diff --git a/src/core/services/utils/url.ts b/src/core/services/utils/url.ts index 2f21fe6fd..f0148b84c 100644 --- a/src/core/services/utils/url.ts +++ b/src/core/services/utils/url.ts @@ -504,7 +504,7 @@ export class CoreUrlUtilsProvider { */ removeProtocolAndWWW(url: string): string { // Remove protocol. - url = url.replace(/.*?:\/\//g, ''); + url = url.replace(/^.*?:\/\//, ''); // Remove www. url = url.replace(/^www./, '');