MOBILE-3163 core: Check site URL when treating pluginfile URLs

main
Dani Palou 2019-09-17 12:34:34 +02:00
parent eb19e61a2d
commit 7471f54f9c
3 changed files with 22 additions and 4 deletions

View File

@ -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;
}

View File

@ -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.
*

View File

@ -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;
}