From c479e904ddaf1d94a18c84638e3df1109f02b616 Mon Sep 17 00:00:00 2001 From: Christian Stocker Date: Thu, 20 Mar 2003 09:43:09 +0000 Subject: fix for bug #22786 ("Crash when trying to call DomAttribute's set_namespace method") --- ext/domxml/php_domxml.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'ext/domxml/php_domxml.c') diff --git a/ext/domxml/php_domxml.c b/ext/domxml/php_domxml.c index 31e2c259f2..f7782e791e 100644 --- a/ext/domxml/php_domxml.c +++ b/ext/domxml/php_domxml.c @@ -3339,7 +3339,11 @@ PHP_FUNCTION(domxml_node_set_namespace) /* if node is in a document, search for an already existing namespace */ if (nodep->doc != NULL) { - nsptr = xmlSearchNsByHref(nodep->doc, nodep, (xmlChar*) uri); + if (nodep->type == XML_ATTRIBUTE_NODE) { + nsptr = xmlSearchNsByHref(nodep->doc, nodep->parent, (xmlChar*) uri); + } else { + nsptr = xmlSearchNsByHref(nodep->doc, nodep, (xmlChar*) uri); + } } else { nsptr = NULL; } @@ -3354,9 +3358,13 @@ PHP_FUNCTION(domxml_node_set_namespace) sprintf(prefixtmp, "a%d", random); prefix = prefixtmp; } - nsptr = xmlNewNs(nodep, uri, prefix); + if (nodep->type == XML_ATTRIBUTE_NODE) { + nsptr = xmlNewNs(nodep->parent, uri, prefix); + } else { + nsptr = xmlNewNs(nodep, uri, prefix); + } } - + xmlSetNs(nodep, nsptr); } /* }}} */ -- cgit v1.2.1