diff --git a/common/web/types/src/kpj/kpj-file-reader.ts b/common/web/types/src/kpj/kpj-file-reader.ts index 29ffe8009d9..d005e0a0abb 100644 --- a/common/web/types/src/kpj/kpj-file-reader.ts +++ b/common/web/types/src/kpj/kpj-file-reader.ts @@ -117,7 +117,13 @@ export class KPJFileReader { * @param source KVKSourceFile */ private boxArrays(source: KPJFile) { - boxXmlArray(source.KeymanDeveloperProject?.Files, 'File'); + if(!source.KeymanDeveloperProject) { + return source; + } + if(!source.KeymanDeveloperProject.Files || typeof source.KeymanDeveloperProject.Files == 'string') { + source.KeymanDeveloperProject.Files = {File:[]}; + } + boxXmlArray(source.KeymanDeveloperProject.Files, 'File'); return source; } } \ No newline at end of file diff --git a/common/web/types/test/fixtures/kpj/project-missing-file/project_missing_file.kpj b/common/web/types/test/fixtures/kpj/project-missing-file/project_missing_file.kpj new file mode 100644 index 00000000000..38fa0201781 --- /dev/null +++ b/common/web/types/test/fixtures/kpj/project-missing-file/project_missing_file.kpj @@ -0,0 +1,12 @@ + + + + $PROJECTPATH + False + False + False + keyboard + + + + diff --git a/common/web/types/test/fixtures/kpj/project-missing-file/project_missing_files.kpj b/common/web/types/test/fixtures/kpj/project-missing-file/project_missing_files.kpj new file mode 100644 index 00000000000..6033b4de103 --- /dev/null +++ b/common/web/types/test/fixtures/kpj/project-missing-file/project_missing_files.kpj @@ -0,0 +1,10 @@ + + + + $PROJECTPATH + False + False + False + keyboard + + diff --git a/common/web/types/test/kpj/test-kpj-file-reader.ts b/common/web/types/test/kpj/test-kpj-file-reader.ts index 12c1e7a134e..cbebdd79207 100644 --- a/common/web/types/test/kpj/test-kpj-file-reader.ts +++ b/common/web/types/test/kpj/test-kpj-file-reader.ts @@ -123,4 +123,34 @@ describe('kpj-file-reader', function () { assert.isEmpty(f.details); assert.lengthOf(f.childFiles, 0); }); + + it('should load a v1.0 keyboard project with missing ', function() { + const path = makePathToFixture('kpj', 'project-missing-file', 'project_missing_file.kpj'); + const input = fs.readFileSync(path); + const reader = new KPJFileReader(callbacks); + const kpj = reader.read(input); + reader.validate(kpj); + if(callbacks.messages.length) { + callbacks.printMessages(); + } + assert.equal(callbacks.messages.length, 0); + assert.lengthOf(kpj.KeymanDeveloperProject.Files.File, 0); + const project = reader.transform(path, kpj); + assert.equal(callbacks.messages.length, 0); + assert.isNotNull(project); + }); + + it('should load a v1.0 keyboard project with missing ', function() { + const path = makePathToFixture('kpj', 'project-missing-file', 'project_missing_files.kpj'); + const input = fs.readFileSync(path); + const reader = new KPJFileReader(callbacks); + const kpj = reader.read(input); + reader.validate(kpj); + assert.equal(callbacks.messages.length, 0); + assert.lengthOf(kpj.KeymanDeveloperProject.Files.File, 0); + const project = reader.transform(path, kpj); + assert.equal(callbacks.messages.length, 0); + assert.isNotNull(project); + }); + });