diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f00d1e8..b6c58562 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## [Unreleased] +## [v1.13.1] - 2024-07-22 + +### Fixed + +- Fixed TypeError occurring for files with non UTF-8 encoding while parsing. + ## [v1.13.0] - 2024-07-10 ### Chore @@ -118,7 +124,9 @@ Newer releases follow the [Keep a Changelog](https://keepachangelog.com) format. - Stable release - Removed libxmljs from package.json -[Unreleased]: https://github.com/postmanlabs/wsdl-to-postman/compare/v1.13.0...HEAD +[Unreleased]: https://github.com/postmanlabs/wsdl-to-postman/compare/v1.13.1...HEAD + +[v1.13.1]: https://github.com/postmanlabs/wsdl-to-postman/compare/v1.13.0...v1.13.1 [v1.13.0]: https://github.com/postmanlabs/wsdl-to-postman/compare/v1.12.3...v1.13.0 diff --git a/lib/XMLParser.js b/lib/XMLParser.js index 14372c84..6f3234e4 100644 --- a/lib/XMLParser.js +++ b/lib/XMLParser.js @@ -73,7 +73,14 @@ class XMLParser { if (!xmlDocumentContent) { return ''; } - return fastXMLParser.parse(fixComments(xmlDocumentContent), optionsForFastXMLParser); + + try { + return fastXMLParser.parse(fixComments(xmlDocumentContent), optionsForFastXMLParser); + } + catch (_e) { + // ignore errors while parsing data + return ''; + } } /** diff --git a/package-lock.json b/package-lock.json index d0736338..ca6eecfb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@postman/wsdl-to-postman", - "version": "1.13.0", + "version": "1.13.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@postman/wsdl-to-postman", - "version": "1.13.0", + "version": "1.13.1", "license": "Apache-2.0", "dependencies": { "ajv": "8.1.0", diff --git a/package.json b/package.json index 9d110cf9..415467b0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@postman/wsdl-to-postman", - "version": "1.13.0", + "version": "1.13.1", "description": "Convert a given WSDL specification (1.1) to Postman Collection", "main": "index.js", "bin": { diff --git a/test/unit/XMLParser.test.js b/test/unit/XMLParser.test.js index 78bc23e9..85c98551 100644 --- a/test/unit/XMLParser.test.js +++ b/test/unit/XMLParser.test.js @@ -204,3 +204,40 @@ describe('XMLparser parseObjectToXML', function () { }); }); + +describe('XMLParser safeParseToObject', function () { + const xmlParser = new XMLParser({}); + + it('should return an empty string when input is an empty file', function () { + let parsed = xmlParser.safeParseToObject(''); + expect(parsed).to.equal(''); + }); + + it('should return an empty string when input is null', function () { + let parsed = xmlParser.safeParseToObject(null); + expect(parsed).to.equal(''); + }); + + it('should return an empty string when input is undefined', function () { + let parsed = xmlParser.safeParseToObject(undefined); + expect(parsed).to.equal(''); + }); + + it('should return an object when input is valid XML', function () { + const validXML = ` + User + Library + Reminder + Hello + `; + let parsed = xmlParser.safeParseToObject(validXML); + expect(parsed).to.be.an('object'); + expect(parsed).to.have.own.property('note'); + }); + + it('should return an empty string when fast-zml-parser fails to parse data', function () { + const invalidXML = '€¯!¢s1≤TO¿˛•LH¥Ò‘⁄∞E»ËòŶTìæv◊ '; + let parsed = xmlParser.safeParseToObject(invalidXML); + expect(parsed).to.equal(''); + }); +});