summaryrefslogtreecommitdiff
path: root/ext/domxml/php_domxml.c
diff options
context:
space:
mode:
authorChristian Stocker <chregu@php.net>2003-01-06 10:00:34 +0000
committerChristian Stocker <chregu@php.net>2003-01-06 10:00:34 +0000
commit562fa5b78f8248c508f5164d7e6b763a016f5485 (patch)
treea95c059a8ecbee6109758c2659344f30b3b3de87 /ext/domxml/php_domxml.c
parent1fcbd36e6df7ea5797e8c86dfb9b1c49aa343b06 (diff)
downloadphp-git-562fa5b78f8248c508f5164d7e6b763a016f5485.tar.gz
- fix crash in domxml_node_insert_before() (by Lukas Schröder)
Diffstat (limited to 'ext/domxml/php_domxml.c')
-rw-r--r--ext/domxml/php_domxml.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/ext/domxml/php_domxml.c b/ext/domxml/php_domxml.c
index 38b407d186..6c36be3176 100644
--- a/ext/domxml/php_domxml.c
+++ b/ext/domxml/php_domxml.c
@@ -2400,9 +2400,40 @@ PHP_FUNCTION(domxml_node_insert_before)
DOMXML_GET_OBJ(child, node, le_domxmlnodep);
+ new_child = NULL;
+
if (ref != NULL) {
DOMXML_GET_OBJ(refp, ref, le_domxmlnodep);
- new_child = xmlAddPrevSibling(refp, child);
+
+ /*
+ * The following code is from libxml2/tree.c
+ * libxml does free textnodes, if there are adjacent TEXT nodes
+ * This is bad behaviour for domxml, since then we have have reference
+ * to undefined nodes. The idea here is, that we do this text comparison
+ * by ourself and not free the nodes. and only if libxml2 won't do any harm
+ * call the function from libxml2.
+ * The code is exactly the same as in libxml2, only xmlFreeNode was taken away.
+ */
+
+ if (child->type == XML_TEXT_NODE) {
+ if (refp->type == XML_TEXT_NODE) {
+ xmlChar *tmp;
+
+ tmp = xmlStrdup(child->content);
+ tmp = xmlStrcat(tmp, refp->content);
+ xmlNodeSetContent(refp, tmp);
+ xmlFree(tmp);
+ new_child = refp;
+ }
+ if ((refp->prev != NULL) && (refp->prev->type == XML_TEXT_NODE)
+ && (refp->name == refp->prev->name)) {
+ xmlNodeAddContent(refp->prev, child->content);
+ new_child = refp->prev;
+ }
+ }
+
+ if (new_child == NULL)
+ new_child = xmlAddPrevSibling(refp, child);
} else {
/* first unlink node, if child is already a child of parent
for some strange reason, this is needed