summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Watkins <krakjoe@php.net>2017-01-25 20:59:37 +0000
committerJoe Watkins <krakjoe@php.net>2017-01-25 20:59:37 +0000
commitf6f2855ecdf37186f96cd504d7b4b8c6e8d595f4 (patch)
tree4e8a2b6ddc88efd843c462cd03566f92d0703eea
parent519b0dc886aed287e5c3472df9c879186f5112c2 (diff)
parent721a189742acc6fb6c2c6d98ce86eebe4e34d42a (diff)
downloadphp-git-f6f2855ecdf37186f96cd504d7b4b8c6e8d595f4.tar.gz
Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0: Fix bug #54382 (getAttributeNodeNS doesn't get xmlns* attributes) Added (failing) testcase for bug #54382
-rw-r--r--ext/dom/element.c32
-rw-r--r--ext/dom/tests/bug54382.phpt27
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