From 789eb299b045e600aa4b86379d466c221700288d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 23 Aug 2019 15:11:36 +0200 Subject: [PATCH] MOBILE-3068 page: Fix base64 images shown --- src/directives/external-content.ts | 11 +++++++++++ src/directives/format-text.ts | 11 +++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/directives/external-content.ts b/src/directives/external-content.ts index 68937d899..4043976aa 100644 --- a/src/directives/external-content.ts +++ b/src/directives/external-content.ts @@ -49,6 +49,8 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges { protected logger; protected initialized = false; + invalid = false; + constructor(element: ElementRef, logger: CoreLoggerProvider, private filepoolProvider: CoreFilepoolProvider, private platform: Platform, private sitesProvider: CoreSitesProvider, private domUtils: CoreDomUtilsProvider, private urlUtils: CoreUrlUtilsProvider, private appProvider: CoreAppProvider, private utils: CoreUtilsProvider) { @@ -141,6 +143,15 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges { } } else { + this.invalid = true; + + return; + } + + // Avoid handling data url's. + if (url.indexOf('data:') === 0) { + this.invalid = true; + return; } diff --git a/src/directives/format-text.ts b/src/directives/format-text.ts index ea7b02b9a..c04732203 100644 --- a/src/directives/format-text.ts +++ b/src/directives/format-text.ts @@ -409,7 +409,12 @@ export class CoreFormatTextDirective implements OnChanges { // Walk through the content to find images, and add our directive. images.forEach((img: HTMLElement) => { this.addMediaAdaptClass(img); - externalImages.push(this.addExternalContent(img)); + + const externalImage = this.addExternalContent(img); + if (!externalImage.invalid) { + externalImages.push(externalImage); + } + if (this.utils.isTrueOrOne(this.adaptImg) && !img.classList.contains('icon')) { this.adaptImage(img); } @@ -475,7 +480,9 @@ export class CoreFormatTextDirective implements OnChanges { promise = Promise.resolve(); } - return promise.then(() => { + return promise.catch(() => { + // Ignore errors. So content gets always shown. + }).then(() => { return div; }); });