From 8cbc1f5635dd7f5a8bf0ec6602f77dfa87ae5fc5 Mon Sep 17 00:00:00 2001 From: jojohoch <joachim.hoch@iqb.hu-berlin.de> Date: Tue, 22 Feb 2022 09:50:22 +0100 Subject: [PATCH] Fix `handleClozeElements` on sanitize the unit definition Since the array of 'ClozeElements' can be empty, it must be checked --- projects/common/util/unit-definition-sanitizer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/common/util/unit-definition-sanitizer.ts b/projects/common/util/unit-definition-sanitizer.ts index 19f9e0a36..d3f4baea2 100644 --- a/projects/common/util/unit-definition-sanitizer.ts +++ b/projects/common/util/unit-definition-sanitizer.ts @@ -94,7 +94,7 @@ export class UnitDefinitionSanitizer { */ private static handleClozeElements(elementList: UIElement[]): void { const clozeElements = elementList.filter(element => element.type === 'cloze'); - if (clozeElements[0].text) { + if (clozeElements.length && clozeElements[0].text) { clozeElements.forEach((element: Record<string, any>) => { const replacedText = element.text.replace(/\\i|\\z|\\r/g, (match: string) => { switch (match) { -- GitLab