xml-js icon indicating copy to clipboard operation
xml-js copied to clipboard

Doesn’t handle invalid characters

Open leafac opened this issue 5 years ago • 2 comments

Run the following program:

const xmlJs = require("xml-js");
const fs = require("fs");
fs.writeFileSync(
  "example.xml",
  xmlJs.js2xml(
    {
      example: {
        _text: "A control character (backspace): \b"
      }
    },
    { compact: true }
  )
);

According to https://www.xmlvalidation.com, the produced example.xml is invalid. xml-js could provide an option to clean these characters (see what xmlbuilder is doing).

leafac avatar Mar 27 '20 20:03 leafac

Just another example: the "&" character is not encoded as "&" example on runkit

yrtimiD avatar Jun 04 '20 09:06 yrtimiD

{
   "example": {
      "#text": "A control character (backspace): \b"
   }
}

may be converted to xml

<?xml version="1.0" encoding="UTF-8"?>
<example>A control character (backspace): \b</example>

javadev avatar Apr 28 '23 22:04 javadev