Double Entity Decoding

57 views
Skip to first unread message

Cooper

unread,
Dec 20, 2012, 9:12:34 AM12/20/12
to wsdl2obj...@googlegroups.com
I believe the code is double decoding XML entities.  In USAdditions on line 71 - xmlNodeListGetString will decode HTML entities if the 3rd argument is 1, which it is.  Then, at the end of the function, we call [NSString stringByUnescapingXML] which will again, escape XML entities.  If found this because I was sending data that already encoded to the client.  

Example:
Data before being placed in xml -  <
XML in Transport -  <
After xmlNodeListGetString --  <
After stringByUnescapingXML -          <

I got the information on xmlNodeListGetString from http://xmlsoft.org/html/libxml-tree.html#xmlNodeListGetString

I have a very basic understanding of libxml and would like someone with more knowledge to confirm this before I would try to submit an edit for the file.

Thanks,
Brian

Cooper

unread,
Dec 20, 2012, 11:26:44 AM12/20/12
to wsdl2obj...@googlegroups.com
While investigating this, I have found that there is a method in libxml that can handle encoding entities as well.


The only difference I've found with this encoding and - (NSString *)stringByEscapingXML is that xmlEncodeSpecialChars does not encode ' ( apostrophes ) which I don't think is necessary.

So I added another method similar to xmlString in USAdditions:

- (const xmlChar *)xmlStringForDoc:(xmlDocPtr)doc

{

    return xmlEncodeSpecialChars(doc, (xmlChar *)[self UTF8String]);

}


And in 


- (xmlNodePtr)xmlNodeForDoc:(xmlDocPtr)doc elementName:(NSString *)elName elementNSPrefix:(NSString *)elNSPrefix


I changed 


xmlNodePtr node = xmlNewDocNode(doc, NULL, [nodeName xmlString], [self xmlString]);

to

xmlNodePtr node = xmlNewDocNode(doc, NULL, [nodeName xmlStringForDoc:doc], [self xmlStringForDoc:doc]);


It would be great to have this reviewed from someone more familiar with libxml and the project.


Thanks,

Brian

Reply all
Reply to author
Forward
0 new messages