[xml] xmlAddNextSibling, xmlAddPrevSibling, etc. allowing text nodes as siblings without merging them



I assume it's a bug. In xmlAddPrevSibling, the check is done as follow:

    if (elem->type == XML_TEXT_NODE) {
        if (cur->type == XML_TEXT_NODE) {
            xmlChar *tmp;

            tmp = xmlStrdup(elem->content);
            tmp = xmlStrcat(tmp, cur->content);
            xmlNodeSetContent(cur, tmp);
            xmlFree(tmp);
            xmlFreeNode(elem);
            return(cur);
        }
        if ((cur->prev != NULL) && (cur->prev->type == XML_TEXT_NODE) &&
            (cur->name == cur->prev->name)) {
            xmlNodeAddContent(cur->prev, elem->content);
            xmlFreeNode(elem);
            return(cur->prev);
        }
 
which means that if you have something like

<a/>prev<cur/>

adding a text node before <cur/> does not merge the text. I don't understand why it's checking for cur->name == cur->prev->name instead of elem->name == cur->prev->name.

I also wonder how much of problem it is to keep text nodes unmerged (as I believe it's possible when handling multiple cdata sections or entities, etc like in:


<![CDATA[a]]>b<![CDATA[c]]>


Regards,
Jerome






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]