From 44e48fc8d1b484b906e5379edacffec800059654 Mon Sep 17 00:00:00 2001 From: Rusty Geldmacher Date: Thu, 27 Apr 2023 11:58:06 -0400 Subject: [PATCH] Update xml2js And fixed the resulting breakage. --- package-lock.json | 6 +++--- package.json | 2 +- src/lib/cda/cda.js | 6 ++++-- src/lib/cda/cda.spec.js | 15 +++++++++++++++ 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 90eba481a..1997bf808 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3972,9 +3972,9 @@ "dev": true }, "xml2js": { - "version": "0.4.23", - "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz", - "integrity": "sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==", + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.5.0.tgz", + "integrity": "sha512-drPFnkQJik/O+uPKpqSgr22mpuFHqKdbS835iAQrUC73L2F5WkboIRd63ai/2Yg6I1jzifPFKH2NTK+cfglkIA==", "requires": { "sax": ">=0.6.0", "xmlbuilder": "~11.0.0" diff --git a/package.json b/package.json index 40b1d5528..19d2af8eb 100644 --- a/package.json +++ b/package.json @@ -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" } diff --git a/src/lib/cda/cda.js b/src/lib/cda/cda.js index ac43b518b..945a15263 100644 --- a/src/lib/cda/cda.js +++ b/src/lib/cda/cda.js @@ -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); }); }); diff --git a/src/lib/cda/cda.spec.js b/src/lib/cda/cda.spec.js index 6f8e61f81..e1dbdf8bd 100644 --- a/src/lib/cda/cda.spec.js +++ b/src/lib/cda/cda.spec.js @@ -38,6 +38,21 @@ describe('cda', function () { .catch((err) => done(err)); }); + it('should return an object with prototype', function (done) { + let data = ' '; + 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(' ') .then(() => done(new Error(`parseSrcData should have failed!`)))