Skip to content

Commit

Permalink
fix(index): catch empty file vars before unrtf parses them
Browse files Browse the repository at this point in the history
  • Loading branch information
Frazer Smith committed Oct 27, 2020
1 parent 81af8a4 commit 789afbd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ class UnRTF {
printVersionInfo: { arg: '--version', type: 'boolean' }
};

// UnRTF still attempts to convert empty strings/files, so catch them here before
if (file === undefined || Object.keys(file).length === 0) {
throw new Error('File missing');
}

try {
const args = await parseOptions(options, acceptedOptions);
args.push(file);
Expand Down
14 changes: 14 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,18 @@ describe('convert function', () => {
expect(err.message).toEqual("Invalid option provided 'outputMp3'");
});
});

test('Should return an Error object if file is missing', async () => {
const unRtf = new UnRTF(testBinaryPath);
const options = {
noPictures: true,
outputHtml: 'sure'
};

await unRtf.convert(undefined, options).catch((err) => {
expect(err.message).toEqual(
"File missing"
);
});
});
});

0 comments on commit 789afbd

Please sign in to comment.