diff --git a/packages/app-cli/tests/enex_to_md/resource_with_missing_encoding.enex b/packages/app-cli/tests/enex_to_md/resource_with_missing_encoding.enex new file mode 100644 index 0000000000..25c0212ac3 --- /dev/null +++ b/packages/app-cli/tests/enex_to_md/resource_with_missing_encoding.enex @@ -0,0 +1,14 @@ + + + + + test.json + + + +]]> + +20191002T075850Z +20191002T075850Z +48.795471191406259.809423921920198398.0Laurentdesktop.mac +eyAidGVzdCI6IDEyMyB9application/json00test.jsonfalse \ No newline at end of file diff --git a/packages/lib/import-enex-md-gen.test.ts b/packages/lib/import-enex-md-gen.test.ts index f2ff886ff1..a5e4062dfa 100644 --- a/packages/lib/import-enex-md-gen.test.ts +++ b/packages/lib/import-enex-md-gen.test.ts @@ -202,6 +202,18 @@ describe('import-enex-md-gen', () => { expect(Resource.fullPath(resource).endsWith('.mscz')).toBe(true); }); + it('should handle resources without encoding', async () => { + // Handle case where the resource has a certain extension, eg. "mscz" + // and a mime type that doesn't really match (application/zip). In that + // case we want to make sure that the file is not converted to a .zip + // file. Fixes https://discourse.joplinapp.org/t/import-issue-evernote-enex-containing-musescore-file-mscz/31394/1 + await importEnexFile('resource_with_missing_encoding.enex'); + const resource = (await Resource.all())[0]; + const resourcePath = Resource.fullPath(resource); + const content = await readFile(resourcePath, 'utf-8'); + expect(content).toBe('{ "test": 123 }'); + }); + it('should sanitize resource filenames with slashes', async () => { await importEnexFile('resource_filename_with_slashes.enex'); const resource: ResourceEntity = (await Resource.all())[0]; diff --git a/packages/lib/import-enex.ts b/packages/lib/import-enex.ts index 5d19aa6e3d..fadf3cc731 100644 --- a/packages/lib/import-enex.ts +++ b/packages/lib/import-enex.ts @@ -150,12 +150,16 @@ async function processNoteResource(resource: ExtractedResource) { // Some resources have no data, go figure, so we need a special case for this. await handleNoDataResource(resource, true); } else { - if (resource.dataEncoding === 'base64') { + // If encoding is not specified, it defaults to base64. + // Source: enex.dtd: + const dataEncoding = resource.dataEncoding ? resource.dataEncoding : 'base64'; + + if (dataEncoding === 'base64') { const decodedFilePath = `${resource.dataFilePath}.decoded`; await decodeBase64File(resource.dataFilePath, decodedFilePath); resource.dataFilePath = decodedFilePath; - } else if (resource.dataEncoding) { - throw new Error(`Cannot decode resource with encoding: ${resource.dataEncoding}`); + } else if (dataEncoding) { + throw new Error(`Cannot decode resource with encoding: ${dataEncoding}`); } const stats = await shim.fsDriver().stat(resource.dataFilePath); diff --git a/packages/tools/cspell/dictionary4.txt b/packages/tools/cspell/dictionary4.txt index 9861c31ced..0cc94172c1 100644 --- a/packages/tools/cspell/dictionary4.txt +++ b/packages/tools/cspell/dictionary4.txt @@ -209,4 +209,5 @@ SPSSO IDPSSO nameid attrname -dpkg \ No newline at end of file +dpkg +ATTLIST \ No newline at end of file