From dc2bbe8af1da5f408762fe0bb3ad894fdcd844c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= <crazyserver@gmail.com>
Date: Tue, 26 Oct 2021 16:23:09 +0200
Subject: [PATCH] MOBILE-3899 core: Fix non-null assertion warnings on linter

---
 .../features/h5p/components/h5p-iframe/h5p-iframe.ts     | 2 +-
 src/core/services/utils/text.ts                          | 4 ++--
 src/core/services/utils/time.ts                          | 8 ++++----
 src/core/singletons/colors.ts                            | 9 +++++++--
 4 files changed, 14 insertions(+), 9 deletions(-)

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 ? ' ' : '<br>');
 
@@ -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;
     }
 
     /**