diff --git a/src/core/features/h5p/components/h5p-iframe/h5p-iframe.ts b/src/core/features/h5p/components/h5p-iframe/h5p-iframe.ts index 5a921c6f8..1af3f74d2 100644 --- a/src/core/features/h5p/components/h5p-iframe/h5p-iframe.ts +++ b/src/core/features/h5p/components/h5p-iframe/h5p-iframe.ts @@ -63,7 +63,7 @@ export class CoreH5PIframeComponent implements OnChanges, OnDestroy { ) { this.logger = CoreLogger.getInstance('CoreH5PIframeComponent'); - this.site = CoreSites.getCurrentSite()!; + this.site = CoreSites.getRequiredCurrentSite(); this.siteId = this.site.getId(); this.siteCanDownload = this.site.canDownloadFiles() && !CoreH5P.isOfflineDisabledInSite(); diff --git a/src/core/services/utils/text.ts b/src/core/services/utils/text.ts index a0b157901..2ea31bf2b 100644 --- a/src/core/services/utils/text.ts +++ b/src/core/services/utils/text.ts @@ -254,7 +254,7 @@ export class CoreTextUtilsProvider { // First, we use a regexpr. text = text.replace(/(<([^>]+)>)/ig, ''); // Then, we rely on the browser. We need to wrap the text to be sure is HTML. - text = this.convertToElement(text).textContent!; + text = this.convertToElement(text).textContent || ''; // Recover or remove new lines. text = this.replaceNewLines(text, singleLine ? ' ' : '
'); @@ -370,7 +370,7 @@ export class CoreTextUtilsProvider { */ decodeHTMLEntities(text: string): string { if (text) { - text = this.convertToElement(text).textContent!; + text = this.convertToElement(text).textContent || ''; } return text; diff --git a/src/core/services/utils/time.ts b/src/core/services/utils/time.ts index b0c8ae3a2..684c741b0 100644 --- a/src/core/services/utils/time.ts +++ b/src/core/services/utils/time.ts @@ -295,19 +295,19 @@ export class CoreTimeUtilsProvider { * @return Readable date. */ userDate(timestamp: number, format?: string, convert: boolean = true, fixDay: boolean = true, fixHour: boolean = true): string { - format = Translate.instant(format ? format : 'core.strftimedaydatetime'); + format = Translate.instant(format ? format : 'core.strftimedaydatetime') as string; if (fixDay) { - format = format!.replace(/%d/g, '%e'); + format = format.replace(/%d/g, '%e'); } if (fixHour) { - format = format!.replace('%I', '%l'); + format = format.replace('%I', '%l'); } // Format could be in PHP format, convert it to moment. if (convert) { - format = this.convertPHPToMoment(format!); + format = this.convertPHPToMoment(format); } return moment(timestamp).format(format); diff --git a/src/core/singletons/colors.ts b/src/core/singletons/colors.ts index eea420a06..9256f5154 100644 --- a/src/core/singletons/colors.ts +++ b/src/core/singletons/colors.ts @@ -64,7 +64,12 @@ export class CoreColors { document.body.appendChild(d); // Color in RGB . - const rgba = getComputedStyle(d).color.match(/\d+/g)!.map((a) => parseInt(a, 10)); + const matches = getComputedStyle(d).color.match(/\d+/g) || []; + if (matches.length == 0) { + return ''; + } + + const rgba = matches.map((a) => parseInt(a, 10)); const hex = [0,1,2].map( (idx) => this.componentToHex(rgba[idx]), @@ -72,7 +77,7 @@ export class CoreColors { document.body.removeChild(d); - return '#'+hex; + return '#' + hex; } /**