Browse Source

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
pull/2357/head
Joe Watkins 10 years ago
parent
commit
f6f2855ecd
No known key found for this signature in database GPG Key ID: F9BA0ADA31CBD89E
  1. 32
      ext/dom/element.c
  2. 27
      ext/dom/tests/bug54382.phpt

32
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 */

27
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
Loading…
Cancel
Save