mirror of
https://github.com/laurent22/joplin.git
synced 2025-02-01 19:15:01 +02:00
All: Fixes #8699: Prevent application from being stuck when importing an invalid ENEX file
This commit is contained in:
parent
9666ea6648
commit
7882237e24
18
packages/app-cli/tests/enex_to_md/invalid_html.enex
Normal file
18
packages/app-cli/tests/enex_to_md/invalid_html.enex
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE en-export SYSTEM "http://xml.evernote.com/pub/evernote-export4.dtd">
|
||||
<en-export export-date="20230811T195236Z" application="Evernote" version="10.58.8">
|
||||
<note>
|
||||
<title>DSCN0716.JPG</title>
|
||||
<created>20130228T193612Z</created>
|
||||
<updated>20230616T123049Z</updated>
|
||||
<tag>Eye-Fi</tag>
|
||||
<tag>2013-02-27</tag>
|
||||
<tag>records</tag>
|
||||
<note-attributes>
|
||||
</note-attributes>
|
||||
<content>
|
||||
<![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"><en-note><en-media type="image/jpeg" hash="33c6ed66e09569ed167dec1e1fd66b87"/><br/><![CDATA[DSCN0716.JPG]]></en-note> ]]>
|
||||
</content>
|
||||
</note>
|
||||
</en-export>
|
@ -4,7 +4,7 @@ import shim from './shim';
|
||||
const fs = require('fs-extra');
|
||||
const os = require('os');
|
||||
const { filename } = require('./path-utils');
|
||||
import { setupDatabaseAndSynchronizer, switchClient, expectNotThrow, supportDir } from './testing/test-utils';
|
||||
import { setupDatabaseAndSynchronizer, switchClient, expectNotThrow, supportDir, expectThrow } from './testing/test-utils';
|
||||
const { enexXmlToMd } = require('./import-enex-md-gen.js');
|
||||
import importEnex from './import-enex';
|
||||
import Note from './models/Note';
|
||||
@ -153,4 +153,9 @@ describe('import-enex-md-gen', () => {
|
||||
expect(errors[0].message.includes('Note 2')).toBe(true);
|
||||
});
|
||||
|
||||
it('should throw an error and stop if the outer XML is invalid', async () => {
|
||||
const filePath = `${enexSampleBaseDir}/invalid_html.enex`;
|
||||
await expectThrow(async () => importEnex('', filePath));
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -456,7 +456,7 @@ function cssValue(context: any, style: string, propName: string | string[]): str
|
||||
|
||||
return null;
|
||||
} catch (error) {
|
||||
displaySaxWarning(context, error.message);
|
||||
displaySaxWarning(context, `Invalid CSS value: ${error.message}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -356,7 +356,7 @@ export default async function importEnex(parentFolderId: string, filePath: strin
|
||||
const fileToProcess = await preProcessFile(filePath);
|
||||
const needToDeleteFileToProcess = fileToProcess !== filePath;
|
||||
|
||||
return new Promise((resolve) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const progressState = {
|
||||
loaded: 0,
|
||||
created: 0,
|
||||
@ -491,6 +491,11 @@ export default async function importEnex(parentFolderId: string, filePath: strin
|
||||
|
||||
saxStream.on('error', function(error: any) {
|
||||
importOptions.onError(createErrorWithNoteTitle(this, error));
|
||||
|
||||
// We need to reject the promise here, or parsing will get stuck
|
||||
// ("end" handler will never be called).
|
||||
// https://github.com/laurent22/joplin/issues/8699
|
||||
reject(error);
|
||||
});
|
||||
|
||||
saxStream.on('text', handleSaxStreamEvent(function(text: string) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user