rrichards Tue Jul 10 12:26:38 2007 UTC Modified files: /php-src/ext/simplexml simplexml.c /php-src/ext/simplexml/tests bug41947.phpt Log: MFB: fix bug #41947 (SimpleXML incorrectly registers empty strings as namespaces add test http://cvs.php.net/viewvc.cgi/php-src/ext/simplexml/simplexml.c?r1=1.240&r2=1.241&diff_format=u Index: php-src/ext/simplexml/simplexml.c diff -u php-src/ext/simplexml/simplexml.c:1.240 php-src/ext/simplexml/simplexml.c:1.241 --- php-src/ext/simplexml/simplexml.c:1.240 Wed Jul 4 05:05:32 2007 +++ php-src/ext/simplexml/simplexml.c Tue Jul 10 12:26:37 2007 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: simplexml.c,v 1.240 2007/07/04 05:05:32 pollita Exp $ */ +/* $Id: simplexml.c,v 1.241 2007/07/10 12:26:37 rrichards Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -1633,11 +1633,16 @@ 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); @@ -2493,7 +2498,7 @@ { php_info_print_table_start(); php_info_print_table_header(2, "Simplexml support", "enabled"); - php_info_print_table_row(2, "Revision", "$Revision: 1.240 $"); + php_info_print_table_row(2, "Revision", "$Revision: 1.241 $"); php_info_print_table_row(2, "Schema support", #ifdef LIBXML_SCHEMAS_ENABLED "enabled"); http://cvs.php.net/viewvc.cgi/php-src/ext/simplexml/tests/bug41947.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/simplexml/tests/bug41947.phpt diff -u /dev/null php-src/ext/simplexml/tests/bug41947.phpt:1.2 --- /dev/null Tue Jul 10 12:26:38 2007 +++ php-src/ext/simplexml/tests/bug41947.phpt Tue Jul 10 12:26:37 2007 @@ -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
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php