From 4437c698b97adda2779769da2e8f7228f24461f9 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Wed, 6 Sep 2023 11:50:47 -0500 Subject: [PATCH 1/2] fix: js=>xml conversion doesn't change html encoding --- src/convert/streams.ts | 1 + test/convert/streams.test.ts | 23 +++++++++++++++++++++++ yarn.lock | 9 +-------- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/convert/streams.ts b/src/convert/streams.ts index 61ed32234c..64eaeed1db 100644 --- a/src/convert/streams.ts +++ b/src/convert/streams.ts @@ -255,6 +255,7 @@ export class JsToXml extends Readable { indentBy: ' ', ignoreAttributes: false, cdataPropName: '__cdata', + processEntities: false, }); const builtXml = String(builder.build(this.xmlObject)); diff --git a/test/convert/streams.test.ts b/test/convert/streams.test.ts index 685b5291bb..3f26f7a98d 100644 --- a/test/convert/streams.test.ts +++ b/test/convert/streams.test.ts @@ -544,6 +544,29 @@ describe('Streams', () => { expect(jsToXml.read().toString()).to.be.equal(expectedBody); }); + it('should transform js with html encoding to xml', () => { + const xmlObj = { + TestType: { + [XML_NS_KEY]: XML_NS_URL, + foo: '3 results, and 1 other', + many: [{ test: 'first' }, { test: 'second' }], + }, + }; + const jsToXml = new streams.JsToXml(xmlObj); + let expectedBody = XML_DECL; + expectedBody += `\n`; + expectedBody += ' 3 results, and 1 other\n'; + expectedBody += ' \n'; + expectedBody += ' first\n'; + expectedBody += ' \n'; + expectedBody += ' \n'; + expectedBody += ' second\n'; + expectedBody += ' \n'; + expectedBody += '\n'; + + expect(jsToXml.read().toString()).to.be.equal(expectedBody); + }); + it('should transform js object with cdata to xml string', () => { const xmlObj = { TestType: { diff --git a/yarn.lock b/yarn.lock index 55ca7a5d7e..f3950a02ee 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4821,14 +4821,7 @@ semver@^6.0.0, semver@^6.3.0, semver@^6.3.1: resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4" integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA== -semver@^7.3.4, semver@^7.3.7, semver@^7.5.0, semver@^7.5.1: - version "7.5.1" - resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.1.tgz#c90c4d631cf74720e46b21c1d37ea07edfab91ec" - integrity sha512-Wvss5ivl8TMRZXXESstBA4uR5iXgEN/VC5/sOcuXdVLzcdkz4HWetIoRfG5gb5X+ij/G9rw9YoGn3QoQ8OCSpw== - dependencies: - lru-cache "^6.0.0" - -semver@^7.5.4: +semver@^7.3.4, semver@^7.3.7, semver@^7.5.0, semver@^7.5.1, semver@^7.5.4: version "7.5.4" resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e" integrity sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA== From d51ff43f9b1bfd1796c615a8b58bd9ff9e2d5840 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Wed, 6 Sep 2023 11:51:42 -0500 Subject: [PATCH 2/2] test: additional encoded strings --- test/convert/streams.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/convert/streams.test.ts b/test/convert/streams.test.ts index 3f26f7a98d..46f572c52f 100644 --- a/test/convert/streams.test.ts +++ b/test/convert/streams.test.ts @@ -549,7 +549,7 @@ describe('Streams', () => { TestType: { [XML_NS_KEY]: XML_NS_URL, foo: '3 results, and 1 other', - many: [{ test: 'first' }, { test: 'second' }], + many: [{ test: 'firstفst' }, { test: 'secondقnd' }], }, }; const jsToXml = new streams.JsToXml(xmlObj); @@ -557,10 +557,10 @@ describe('Streams', () => { expectedBody += `\n`; expectedBody += ' 3 results, and 1 other\n'; expectedBody += ' \n'; - expectedBody += ' first\n'; + expectedBody += ' firstفst\n'; expectedBody += ' \n'; expectedBody += ' \n'; - expectedBody += ' second\n'; + expectedBody += ' secondقnd\n'; expectedBody += ' \n'; expectedBody += '\n';