From 8c18516f5aa0cf5a694287dd04b0d6e660d673aa Mon Sep 17 00:00:00 2001 From: Rob Richards Date: Tue, 10 Jul 2007 12:26:37 +0000 Subject: [PATCH] MFB: fix bug #41947 (SimpleXML incorrectly registers empty strings as namespaces add test --- ext/simplexml/simplexml.c | 11 ++++++++--- ext/simplexml/tests/bug41947.phpt | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 ext/simplexml/tests/bug41947.phpt diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 9b60779b6f..d60f7a27ec 100644 --- a/ext/simplexml/simplexml.c +++ b/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); diff --git a/ext/simplexml/tests/bug41947.phpt b/ext/simplexml/tests/bug41947.phpt new file mode 100644 index 0000000000..7af9ff8e76 --- /dev/null +++ b/ext/simplexml/tests/bug41947.phpt @@ -0,0 +1,14 @@ +--TEST-- +Bug #41947 (addChild incorrectly registers empty strings as namespaces) +--FILE-- +'); +$grandchild = $xml->addChild('child', null, 'http://myns')->addChild('grandchild', 'hello', ''); + +$gchild = $xml->xpath("//grandchild"); +if (count($gchild) > 0) { + echo $gchild[0]; +} +?> +--EXPECT-- +hello -- 2.50.1