From a6df4e997b951e7075f6cee845b71e15be58be5c Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 4 Feb 2022 12:34:28 +0100 Subject: [PATCH] MOBILE-3833 core: Fix substring errors --- .../filter/mathjaxloader/services/handlers/mathjaxloader.ts | 2 +- src/addons/mod/lesson/services/lesson.ts | 2 +- src/addons/mod/scorm/classes/data-model-12.ts | 4 ++-- src/addons/mod/url/services/url.ts | 4 ++-- src/core/singletons/colors.ts | 4 ++-- src/core/singletons/locutus.ts | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts b/src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts index 40f83f4ba..ad398a11d 100644 --- a/src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts +++ b/src/addons/filter/mathjaxloader/services/handlers/mathjaxloader.ts @@ -190,7 +190,7 @@ export class AddonFilterMathJaxLoaderHandlerService extends CoreFilterDefaultHan protected insertSpan(text: string, start: number, end: number): string { return CoreTextUtils.substrReplace( text, - '' + text.substring(start, end - start + 1) + '', + '' + text.substring(start, end + 1) + '', start, end - start + 1, ); diff --git a/src/addons/mod/lesson/services/lesson.ts b/src/addons/mod/lesson/services/lesson.ts index 7d1418032..4a33b1617 100644 --- a/src/addons/mod/lesson/services/lesson.ts +++ b/src/addons/mod/lesson/services/lesson.ts @@ -760,7 +760,7 @@ export class AddonModLessonProvider { let ignoreCase = ''; if (useRegExp) { - if (expectedAnswer.substring(-2) == '/i') { + if (expectedAnswer.slice(-2) == '/i') { expectedAnswer = expectedAnswer.substring(0, expectedAnswer.length - 2); ignoreCase = 'i'; } diff --git a/src/addons/mod/scorm/classes/data-model-12.ts b/src/addons/mod/scorm/classes/data-model-12.ts index 97889bfdb..8c82d6876 100644 --- a/src/addons/mod/scorm/classes/data-model-12.ts +++ b/src/addons/mod/scorm/classes/data-model-12.ts @@ -748,7 +748,7 @@ export class AddonModScormDataModel12 { const childrenStr = '._children'; const countStr = '._count'; - if (elementModel.substring(elementModel.length - childrenStr.length, elementModel.length) == childrenStr) { + if (elementModel.substring(elementModel.length - childrenStr.length) == childrenStr) { const parentModel = elementModel.substring(0, elementModel.length - childrenStr.length); if (this.dataModel[this.scoId][parentModel] !== undefined) { @@ -756,7 +756,7 @@ export class AddonModScormDataModel12 { } else { this.errorCode = '201'; } - } else if (elementModel.substring(elementModel.length - countStr.length, elementModel.length) == countStr) { + } else if (elementModel.substring(elementModel.length - countStr.length) == countStr) { const parentModel = elementModel.substring(0, elementModel.length - countStr.length); if (this.dataModel[this.scoId][parentModel] !== undefined) { diff --git a/src/addons/mod/url/services/url.ts b/src/addons/mod/url/services/url.ts index 86a2ad5bb..332663f1a 100644 --- a/src/addons/mod/url/services/url.ts +++ b/src/addons/mod/url/services/url.ts @@ -68,7 +68,7 @@ export class AddonModUrlProvider { const download = ['application/zip', 'application/x-tar', 'application/g-zip', 'application/pdf', 'text/html']; let mimetype = CoreMimetypeUtils.getMimeType(extension); - if (url.externalurl.indexOf('.php') != -1 || url.externalurl.substring(-1) === '/' || + if (url.externalurl.indexOf('.php') != -1 || url.externalurl.slice(-1) === '/' || (url.externalurl.indexOf('//') != -1 && url.externalurl.match(/\//g)?.length == 2)) { // Seems to be a web, use HTML mimetype. mimetype = 'text/html'; @@ -158,7 +158,7 @@ export class AddonModUrlProvider { const matches = url.match(/\//g); const extension = CoreMimetypeUtils.getFileExtension(url); - if (!matches || matches.length < 3 || url.substring(-1) === '/' || extension == 'php') { + if (!matches || matches.length < 3 || url.slice(-1) === '/' || extension == 'php') { // Use default icon. return ''; } diff --git a/src/core/singletons/colors.ts b/src/core/singletons/colors.ts index 368b3e99d..40c2cdffe 100644 --- a/src/core/singletons/colors.ts +++ b/src/core/singletons/colors.ts @@ -123,8 +123,8 @@ export class CoreColors { return { red: parseInt(color.substring(0, 2), 16), - green: parseInt(color.substring(2, 2), 16), - blue: parseInt(color.substring(4, 2), 16), + green: parseInt(color.substring(2, 4), 16), + blue: parseInt(color.substring(4, 6), 16), }; } diff --git a/src/core/singletons/locutus.ts b/src/core/singletons/locutus.ts index ac9b5bc3e..be8b74d97 100644 --- a/src/core/singletons/locutus.ts +++ b/src/core/singletons/locutus.ts @@ -123,7 +123,7 @@ function readBytes (str, len, escapedString = false) { const isLowSurrogate = code >= 0xdc00 && code <= 0xdfff if (escapedString && chr === '\\') { - chr = String.fromCharCode(parseInt(str.substring(c + 1, 2), 16)) + chr = String.fromCharCode(parseInt(str.substring(c + 1, c + 3), 16)) escapedChars++ // each escaped sequence is 3 characters. Go 2 chars ahead.