diff options
-rw-r--r-- | ext/dom/element.c | 32 | ||||
-rw-r--r-- | ext/dom/tests/bug54382.phpt | 27 |
2 files changed, 55 insertions, 4 deletions
diff --git a/ext/dom/element.c b/ext/dom/element.c index d9fa381717..df841b6b8a 100644 --- a/ext/dom/element.c +++ b/ext/dom/element.c @@ -921,7 +921,7 @@ Since: DOM Level 2 PHP_FUNCTION(dom_element_get_attribute_node_ns) { zval *id; - xmlNodePtr elemp; + xmlNodePtr elemp, fakeAttrp; xmlAttrPtr attrp; dom_object *intern; size_t uri_len, name_len; @@ -937,10 +937,34 @@ PHP_FUNCTION(dom_element_get_attribute_node_ns) attrp = xmlHasNsProp(elemp, (xmlChar *)name, (xmlChar *)uri); if (attrp == NULL) { - RETURN_NULL(); - } + if (xmlStrEqual((xmlChar *) uri, (xmlChar *)DOM_XMLNS_NAMESPACE)) { + xmlNsPtr nsptr; + nsptr = dom_get_nsdecl(elemp, (xmlChar *)name); + if (nsptr != NULL) { + xmlNsPtr curns; + curns = xmlNewNs(NULL, nsptr->href, NULL); + if (nsptr->prefix) { + curns->prefix = xmlStrdup((xmlChar *) nsptr->prefix); + } + if (nsptr->prefix) { + fakeAttrp = xmlNewDocNode(elemp->doc, NULL, (xmlChar *) nsptr->prefix, nsptr->href); + } else { + fakeAttrp = xmlNewDocNode(elemp->doc, NULL, (xmlChar *)"xmlns", nsptr->href); + } + fakeAttrp->type = XML_NAMESPACE_DECL; + fakeAttrp->parent = elemp; + fakeAttrp->ns = curns; - DOM_RET_OBJ((xmlNodePtr) attrp, &ret, intern); + DOM_RET_OBJ(fakeAttrp, &ret, intern); + } else { + RETURN_NULL(); + } + } else { + RETURN_NULL(); + } + } else { + DOM_RET_OBJ((xmlNodePtr) attrp, &ret, intern); + } } /* }}} end dom_element_get_attribute_node_ns */ diff --git a/ext/dom/tests/bug54382.phpt b/ext/dom/tests/bug54382.phpt new file mode 100644 index 0000000000..fa12b0ef92 --- /dev/null +++ b/ext/dom/tests/bug54382.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #54382 DOMNode::getAttributeNodeNS doesn't get xmlns* attributes +--SKIPIF-- +<?php +require_once('skipif.inc'); +?> +--FILE-- +<?php +$xmlString = '<?xml version="1.0" encoding="utf-8" ?> +<root xmlns="http://ns" xmlns:ns2="http://ns2"> + <ns2:child /> +</root>'; + +$xml=new DOMDocument(); +$xml->loadXML($xmlString); +$de = $xml->documentElement; + +$ns2 = $de->getAttributeNodeNS("http://www.w3.org/2000/xmlns/", "ns2"); +if ($ns2 == NULL) { + echo 'namespace node does not exist.' . "\n"; +} else { + echo 'namespace node prefix=' . $ns2->prefix . "\n"; + echo 'namespace node namespaceURI=' . $ns2->namespaceURI . "\n"; +} +--EXPECT-- +namespace node prefix=ns2 +namespace node namespaceURI=http://ns2 |