Browse Source

MFB: fix bug #41947 (SimpleXML incorrectly registers empty strings as namespaces

add test
PHAR_1_2
Rob Richards 19 years ago
parent
commit
8c18516f5a
  1. 11
      ext/simplexml/simplexml.c
  2. 14
      ext/simplexml/tests/bug41947.phpt

11
ext/simplexml/simplexml.c

@ -1633,11 +1633,16 @@ SXE_METHOD(addChild)
newnode = xmlNewChild(node, NULL, localname, (xmlChar *)value);
if (nsuri != NULL) {
nsptr = xmlSearchNsByHref(node->doc, node, (xmlChar *)nsuri);
if (nsptr == NULL) {
if (nsuri_len == 0) {
newnode->ns = NULL;
nsptr = xmlNewNs(newnode, (xmlChar *)nsuri, prefix);
} else {
nsptr = xmlSearchNsByHref(node->doc, node, (xmlChar *)nsuri);
if (nsptr == NULL) {
nsptr = xmlNewNs(newnode, (xmlChar *)nsuri, prefix);
}
newnode->ns = nsptr;
}
newnode->ns = nsptr;
}
_node_as_zval(sxe, newnode, return_value, SXE_ITER_NONE, (char *)localname, prefix, 0 TSRMLS_CC);

14
ext/simplexml/tests/bug41947.phpt

@ -0,0 +1,14 @@
--TEST--
Bug #41947 (addChild incorrectly registers empty strings as namespaces)
--FILE--
<?php
$xml = simplexml_load_string('<?xml version="1.0" encoding="utf-8"?><root xmlns:myns="http://myns" />');
$grandchild = $xml->addChild('child', null, 'http://myns')->addChild('grandchild', 'hello', '');
$gchild = $xml->xpath("//grandchild");
if (count($gchild) > 0) {
echo $gchild[0];
}
?>
--EXPECT--
hello
Loading…
Cancel
Save