ikastech / x2js

Automatically exported from code.google.com/p/x2js
0 stars 0 forks source link

/ is escaped but should NOT be escaped #36

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
This results in xml-files that looks ugly like this:

...
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
...

The only characters that has to be escaped are: <, &, >, ", '
Also ' should be replaced with &apos;
See: 
http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#En
tities_representing_special_characters_in_XHTML

Replacement code:

    function escapeXmlChars(str) {
        if(typeof(str) == "string")
            return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;');
        else
            return str;
    }

Also the unescapeXmlChars should handle any escaped character (unicode and 
named) and not a small predefined set.

Original issue reported on code.google.com by david.gr...@gmail.com on 5 Feb 2015 at 1:34

GoogleCodeExporter commented 9 years ago
I'll check it (maybe it's already fixed). Thanks for report!

Original comment by abdulla....@gmail.com on 20 May 2015 at 9:58

GoogleCodeExporter commented 9 years ago
I made fork where I fixed the xml escape to behave correct, made the source 
validate with stricter JSHINT config, threw away all old IE support, threw away 
some date-stuff that I could not test, added support to run it in node and 
tested with almost 100% test coverage of what I kept. So I am do not need this 
fix any more, but I guess that other could use that. Are you interested in the 
my updated source?

Original comment by david.gr...@gmail.com on 21 May 2015 at 6:37