nashwaan/xml-js

Attribute value string not converted to HTML esc char by js2xml

vreshos opened this issue · 2 comments

Using xml2js, read in an XML file with a node that has the following attribute:
src_text="& amp; (had to add a space for it to show up in the page)
When using js2xml to save the resulting object back to xml, I get the following output:
src_text="&"
Why isn't src_text value properly escaped with HTML esc character? This only happens when the attribute is a single '&' character. If there is other text, the & is escaped correctly

js2xml(obj, {
    attributeValueFn(v) {
      return v.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
    },
  });

like this code, it work.