]> granicus.if.org Git - php/commitdiff
fix for bug #22786 ("Crash when trying to call DomAttribute's set_namespace method")
authorChristian Stocker <chregu@php.net>
Thu, 20 Mar 2003 09:48:19 +0000 (09:48 +0000)
committerChristian Stocker <chregu@php.net>
Thu, 20 Mar 2003 09:48:19 +0000 (09:48 +0000)
ext/domxml/php_domxml.c

index 91bcb25e153085626b3ce6c2a5ccb2dc1d89da8d..8262c1be38233b82a6f9bdf13b023127d4449533 100644 (file)
@@ -3352,7 +3352,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;
        }
@@ -3367,9 +3371,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);
 }
 /* }}} */