Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Previous invalid decode of XML escape sequences not fixed for 2.4.0 #68

Closed
crolex opened this issue Dec 22, 2020 · 4 comments
Closed

Previous invalid decode of XML escape sequences not fixed for 2.4.0 #68

crolex opened this issue Dec 22, 2020 · 4 comments

Comments

@crolex
Copy link

crolex commented Dec 22, 2020

This previous defect does not seem to be fixed or has retured. I added the noDoubleEncoding:true to the convert() options using version 2.4.0

To Reproduce defect 1:

const xmlbuilder2 = require("xmlbuilder2");
const assert = require("assert");
const originalXML = `<?xml version="1.0"?><example>&lt;p&gt;Hello&lt;/p&gt;</example>`;
console.log("originalXML:", originalXML);
const objectXML = xmlbuilder2.convert(originalXML, { format: "object", noDoubleEncoding: true });
assert.strictEqual( objectXML, {example:'<p>Hello</p>'} );

Result:

AssertionError [ERR_ASSERTION]: Input A expected to strictly equal input B:
+ expected - actual

  {
-   example: '&lt;p&gt;Hello&lt;/p&gt;'
+   example: '<p>Hello</p>'
  }

The decoded XML which contains valid < and > escapes does not result in the expected output as reported by @leafac.
The addition of the noDoubleEncoding:true option also does not correct the round trip XML->JS->XML.

To reproduce defect 2:

const xmlbuilder2 = require("xmlbuilder2");
const assert = require("assert");
const originalXML = `<?xml version="1.0"?><example>&lt;p&gt;Hello&lt;/p&gt;</example>`;
console.log("originalXML:", originalXML);
const objectXML = xmlbuilder2.convert(originalXML, { format: "object", noDoubleEncoding: true });
console.log("objectXML:", JSON.stringify(objectXML, null, 2));
const recreatedXML = xmlbuilder2.convert(objectXML, { format: "xml" });
console.log("recreatedXML:", recreatedXML);
assert.strictEqual(recreatedXML, originalXML);

Result:

AssertionError [ERR_ASSERTION]: Input A expected to strictly equal input B:
+ expected - actual

- '<?xml version="1.0"?><example>&amp;lt;p&amp;gt;Hello&amp;lt;/p&amp;gt;</example>'
+ '<?xml version="1.0"?><example>&lt;p&gt;Hello&lt;/p&gt;</example>'

Originally posted by @crolex in #15 (comment)

@oozcitak
Copy link
Owner

@crolex You are missing the noDoubleEncoding flag in your second example. This line:

const recreatedXML = xmlbuilder2.convert(objectXML, { format: "xml" });

should be:

const recreatedXML = xmlbuilder2.convert(objectXML, { format: "xml", noDoubleEncoding: true });

@jimmythomson
Copy link

I'm seeing the same issue as @crolex using 2.4.0. The use of noDoubleEncoding has no impact.

@jimmythomson
Copy link

Here's a demo of the issue using the first section of code that @crolex posted: https://repl.it/@jimmythomson/xmlbuilder2-issues-68

@oozcitak
Copy link
Owner

noDoubleEncoding prevents re-encoding. It does not decode existing encoded entities. Please see the explanation here: #73 (comment). What you are looking for is probably someting like underscore's unescape. This library doesn't have such a function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants