Skip to content

Commit

Permalink
Merge pull request #9824 from keymanapp/chore/common/kpj-handle-xml-e…
Browse files Browse the repository at this point in the history
…rror

chore(common): handle invalid XML in kpj-file-reader
  • Loading branch information
mcdurdin authored Oct 26, 2023
2 parents 72f7a6e + c645707 commit 762f343
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion common/web/types/src/kpj/kpj-file-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Details/> as '' so we will just delete the empty string
Expand Down
3 changes: 2 additions & 1 deletion developer/src/kmc/src/util/projectLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()}));
Expand Down

0 comments on commit 762f343

Please sign in to comment.