From 7471f54f9c187d4091013c7dfc03c92bab791f59 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 17 Sep 2019 12:34:34 +0200 Subject: [PATCH] MOBILE-3163 core: Check site URL when treating pluginfile URLs --- src/classes/site.ts | 4 ++-- src/providers/utils/text.ts | 18 ++++++++++++++++++ src/providers/utils/url.ts | 4 ++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/classes/site.ts b/src/classes/site.ts index d4988f66a..a038bb3e0 100644 --- a/src/classes/site.ts +++ b/src/classes/site.ts @@ -1404,8 +1404,8 @@ export class CoreSite { return false; } - const siteUrl = this.textUtils.removeEndingSlash(this.urlUtils.removeProtocolAndWWW(this.siteUrl)); - url = this.urlUtils.removeProtocolAndWWW(url); + const siteUrl = this.textUtils.addEndingSlash(this.urlUtils.removeProtocolAndWWW(this.siteUrl)); + url = this.textUtils.addEndingSlash(this.urlUtils.removeProtocolAndWWW(url)); return url.indexOf(siteUrl) == 0; } diff --git a/src/providers/utils/text.ts b/src/providers/utils/text.ts index 9a244b6f7..4ba9574f1 100644 --- a/src/providers/utils/text.ts +++ b/src/providers/utils/text.ts @@ -75,6 +75,24 @@ export class CoreTextUtilsProvider { constructor(private translate: TranslateService, private langProvider: CoreLangProvider, private modalCtrl: ModalController, private sanitizer: DomSanitizer, private platform: Platform) { } + /** + * Add ending slash from a path or URL. + * + * @param {string} text Text to treat. + * @return {string} Treated text. + */ + addEndingSlash(text: string): string { + if (!text) { + return ''; + } + + if (text.slice(-1) != '/') { + return text + '/'; + } + + return text; + } + /** * Given an address as a string, return a URL to open the address in maps. * diff --git a/src/providers/utils/url.ts b/src/providers/utils/url.ts index ac85237d7..295d54ae7 100644 --- a/src/providers/utils/url.ts +++ b/src/providers/utils/url.ts @@ -121,8 +121,8 @@ export class CoreUrlUtilsProvider { return url; } - // Check if is a valid URL (contains the pluginfile endpoint). - if (!this.isPluginFileUrl(url)) { + // Check if is a valid URL (contains the pluginfile endpoint) and belongs to the site. + if (!this.isPluginFileUrl(url) || url.indexOf(this.textUtils.addEndingSlash(siteUrl)) !== 0) { return url; }