diff --git a/src/services/exportImport.test.ts b/src/services/exportImport.test.ts index 64cc2a1..bc66966 100644 --- a/src/services/exportImport.test.ts +++ b/src/services/exportImport.test.ts @@ -13,6 +13,10 @@ describe('exportImport', () => { mockGetAllAsync.mockClear(); }); + it('rejects backups that are not valid JSON', async () => { + await expect(importAllData('not json')).rejects.toThrow('not valid JSON'); + }); + it('rejects backups that are missing required data', async () => { await expect(importAllData('{}')).rejects.toThrow('missing required data'); }); diff --git a/src/services/exportImport.ts b/src/services/exportImport.ts index 0a77f6b..b574241 100644 --- a/src/services/exportImport.ts +++ b/src/services/exportImport.ts @@ -25,7 +25,12 @@ export async function exportAllData(): Promise { } export async function importAllData(json: string) { - const parsed = JSON.parse(json) as Partial; + let parsed: Partial; + try { + parsed = JSON.parse(json) as Partial; + } catch { + throw new Error('This backup is not valid JSON.'); + } if (!Array.isArray(parsed.applications) || !Array.isArray(parsed.resume_versions) || !Array.isArray(parsed.status_history) || !Array.isArray(parsed.reminders)) { throw new Error('This backup is missing required data.'); }