monami7000 / json-xml-rpc

0 stars 0 forks source link

Special chars encoding #12

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
It seems the library produces invalid input when sending string with characters 
as "<" and ">". They are not encoded and, obviously, this leads to invalid xml 
stream.

Reproduce the error is really simple: just send via xmlrpc a string with one of 
these chars.

Original issue reported on code.google.com by gwub...@gmail.com on 1 Oct 2010 at 1:37

GoogleCodeExporter commented 9 years ago
The following unified diff will fix the problem.

I've also attached the diff as a file in case that is preferred.

@@ -684,8 +684,15 @@
            break;

        case 'string':

            xml.push('<string>');

-           xml.push(value.replace(/[<>&]/, function(ch){

-               

+           xml.push(value.replace(/[<>&]/g, function(ch){

+               switch(ch){

+               case '<':

+                   return '<';

+               case '>':

+                   return '>';

+               case '&':

+                   return '&';

+               }

            })); //escape for XML!

            xml.push('</string>');

            break;

Original comment by K.S.H...@gmail.com on 14 Feb 2011 at 5:28

Attachments: