From c6457072791866ef718286a9e77134efa2500666 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Mon, 23 Oct 2023 08:53:30 +0700 Subject: [PATCH] chore(common): handle invalid XML in kpj-file-reader --- common/web/types/src/kpj/kpj-file-reader.ts | 7 ++++++- developer/src/kmc/src/util/projectLoader.ts | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/common/web/types/src/kpj/kpj-file-reader.ts b/common/web/types/src/kpj/kpj-file-reader.ts index cffa2069c64..4457992e227 100644 --- a/common/web/types/src/kpj/kpj-file-reader.ts +++ b/common/web/types/src/kpj/kpj-file-reader.ts @@ -21,7 +21,12 @@ export class KPJFileReader { emptyTag: '' }); - parser.parseString(file, (e: unknown, r: unknown) => { data = r as KPJFile }); + parser.parseString(file, (e: unknown, r: unknown) => { + if(e) { + throw e; + } + data = r as KPJFile; + }); data = this.boxArrays(data); for(let file of data.KeymanDeveloperProject?.Files?.File) { // xml2js imports
as '' so we will just delete the empty string diff --git a/developer/src/kmc/src/util/projectLoader.ts b/developer/src/kmc/src/util/projectLoader.ts index 078f2e31ded..10cd58fc818 100644 --- a/developer/src/kmc/src/util/projectLoader.ts +++ b/developer/src/kmc/src/util/projectLoader.ts @@ -44,8 +44,9 @@ function loadDefaultProjectFromFolder(infile: string, callbacks: CompilerCallbac function loadProjectFromFile(infile: string, callbacks: CompilerCallbacks): KeymanDeveloperProject { const kpjData = callbacks.loadFile(infile); const reader = new KPJFileReader(callbacks); - const kpj = reader.read(kpjData); + let kpj = null; try { + kpj = reader.read(kpjData); reader.validate(kpj); } catch(e) { callbacks.reportMessage(InfrastructureMessages.Error_InvalidProjectFile({message: (e??'').toString()}));