Skip to content

Commit

Permalink
submissionXmlToFieldStream: extend test cases for malformed XML (#1405)
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn authored Feb 18, 2025
1 parent ad40043 commit 7e1cf19
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions test/unit/data/submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,31 @@ describe('submission field streamer', () => {
})));
});

it('should not hang given malformed non-closing xml', (done) => {
fieldsFor(testData.forms.simple).then((fields) => {
const stream = submissionXmlToFieldStream(fields, '<data><meta><instanceID>');
stream.on('data', () => {});
stream.on('end', done); // not hanging/timing out is the assertion here
});
});

it('should not crash given malformed over-closing xml', (done) => {
fieldsFor(testData.forms.simple).then((fields) => {
const stream = submissionXmlToFieldStream(fields, '<data></goodbye></goodbye></goodbye>');
stream.on('data', () => {});
stream.on('end', done); // not hanging/timing out is the assertion here
[
'<data>', // no closing tags
'<data><meta><instanceID>', // no closing tags
'<data></goodbye></goodbye></goodbye>', // over-closing
// trailing content:
'<doc/><boom>',
'<doc/></boom>',
'<doc/> boom',
'<doc></doc><boom>',
'<doc></doc></boom>',
'<doc></doc> boom',
// leading content:
'<boom><doc/>',
'</boom><doc/>',
'boom <doc/>',
'<boom><doc></doc>',
'</boom><doc></doc>',
'boom <doc></doc>',
].forEach(xml => {
it(`should not hang given malformed xml: ${xml}`, (done) => {
fieldsFor(testData.forms.simple).then((fields) => {
const stream = submissionXmlToFieldStream(fields, xml);
stream.on('data', () => {});
stream.on('end', done); // not hanging/timing out is the assertion here
});
});
});

Expand Down

0 comments on commit 7e1cf19

Please sign in to comment.