xmldom
xmldom copied to clipboard
Encode ">" to > during serialization
Symbol ">" is not properly encoded during serialization.
Test code:
var xmldom = require('xmldom');
var domparser = new xmldom.DOMParser;
var xmlserializer = new xmldom.XMLSerializer;
var dom = domparser.parseFromString('<node attr="<>"><></node>');
var s = xmlserializer.serializeToString(dom);
console.log(s);
// outputs '<node attr="<>"><></node>'
thanks it is not required
<node attr="1 < 2 && 2 > 1 "> <> </node>
is well-formed xml
Created foo.xml using this source.
<node attr="1 < 2 && 2 > 1 ">
<>
</node>
Ran it through xmllint.
$ xmllint foo.xml
foo.xml:1: parser error : xmlParseEntityRef: no name
<node attr="1 < 2 && 2 > 1 ">
^
foo.xml:1: parser error : xmlParseEntityRef: no name
<node attr="1 < 2 && 2 > 1 ">
to: bigeasy
hi, you are so fast always . ^_^
it's my fault, && is valid but > is well-formed
i think we need a config about whether the '>' is encoded; In order to meet everyone's taste:)
I don't have an opinion. I might have had an opinion at the time of #25, but not today. With XML, valid is valid.
Is your primary objection that you don't want to rewrite your tests to expect an encoded >, or is it that you prefer to leave them unencoded as a matter of style?
In the beginning, because of my lazy, as your said, keep it as a style is also good.
But I worry about this style may give the user some trouble.
For example: can't pass the tests.
Yes, I was wrong, well-formed XML doesn't require escaping ">" inside character data.
i think we need a config about whether the '>' is encoded; In order to meet everyone's taste:)
However, at least Gecko and Webkit implementations of XMLSerializer do escape ">", so adding such option would be great not only for meeting everyone's taste but for better compatibility with browser javascript :)
Note that escaping of ">" is required in attribute values but not in character data.
Confirmed. We had issue when the serialized XML is parsed by .NET serializer.
+1 for this. Not all XML validators are okay with '>'. Any chance of merging this soon?
- for this! Did the same fix locally but to be production safe i need to do a manual replace of >. Can you merge this soon!