Skip to content

Commit

Permalink
Update xml2js
Browse files Browse the repository at this point in the history
And fixed the resulting breakage.
  • Loading branch information
Rusty Geldmacher committed Apr 27, 2023
1 parent 967e88a commit 44e48fc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"swagger-ui-express": "^4.2.0",
"underscore": "^1.13.1",
"uuid": "^3.3.2",
"xml2js": "^0.4.23"
"xml2js": "^0.5.0"
},
"license": "MIT"
}
6 changes: 4 additions & 2 deletions src/lib/cda/cda.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ module.exports = class cda extends dataHandler {

parseSrcData(data) {
return new Promise((fulfill, reject) => {
parseString(data, { trim: true, explicitCharkey :true, mergeAttrs: true, explicitArray:false }, function (err, result) {
parseString(data, { trim: true, explicitCharkey: true, mergeAttrs: true, explicitArray: false }, function (err, result) {
if (err) {
reject(err);
}
result._originalData=data;
// Need this in order to get Object prototype back into the parsed results
result = JSON.parse(JSON.stringify(result));
result._originalData = data;
fulfill(result);
});
});
Expand Down
15 changes: 15 additions & 0 deletions src/lib/cda/cda.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ describe('cda', function () {
.catch((err) => done(err));
});

it('should return an object with prototype', function (done) {
let data = '<a> <b c="d"/> </a>';
new cda().parseSrcData(data)
.then((result) => {
if (result.__proto__ !== undefined)
{
done();
}
else {
done(new Error(`Parsed data should have object prototype`));
}
})
.catch((err) => done(err));
});

it('should fail while parsing incorrect data.', function (done) {
new cda().parseSrcData('<a b c="d"/> </a>')
.then(() => done(new Error(`parseSrcData should have failed!`)))
Expand Down

0 comments on commit 44e48fc

Please sign in to comment.