cvs: php-src /ext/simplexml simplexml.c /ext/simplexml/tests 027.phpt 030.phpt bug35785.phpt

From: Date: Sun, 05 Mar 2006 14:01:13 +0000
Subject: cvs: php-src /ext/simplexml simplexml.c /ext/simplexml/tests 027.phpt 030.phpt bug35785.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-37116@lists.php.net to get a copy of this message
rrichards Sun Mar 5 14:01:13 2006 UTC Added files: /php-src/ext/simplexml/tests 030.phpt Modified files: /php-src/ext/simplexml simplexml.c /php-src/ext/simplexml/tests 027.phpt bug35785.phpt Log: fix crash passing non-string member to sxe_prop_dim_exists allow offsets to be used when calling isset/unset fix tests add test

http://cvs.php.net/viewcvs.cgi/php-src/ext/simplexml/simplexml.c?r1=1.197&r2=1.198&diff_format=u Index: php-src/ext/simplexml/simplexml.c diff -u php-src/ext/simplexml/simplexml.c:1.197 php-src/ext/simplexml/simplexml.c:1.198 --- php-src/ext/simplexml/simplexml.c:1.197 Thu Mar 2 13:12:45 2006 +++ php-src/ext/simplexml/simplexml.c Sun Mar 5 14:01:13 2006 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: simplexml.c,v 1.197 2006/03/02 13:12:45 dmitry Exp $ */ +/* $Id: simplexml.c,v 1.198 2006/03/05 14:01:13 rrichards Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -626,6 +626,14 @@ xmlAttrPtr attr = NULL; int exists = 0; int test = 0; + zval tmp_zv; + + if (Z_TYPE_P(member) != IS_STRING && Z_TYPE_P(member) != IS_LONG) { + tmp_zv = *member; + zval_copy_ctor(&tmp_zv); + member = &tmp_zv; + convert_to_string(member); + } sxe = php_sxe_fetch_object(object TSRMLS_CC); @@ -655,13 +663,28 @@ if (node) { if (attribs) { - while (attr) { - if ((!test || !xmlStrcmp(attr->name, sxe->iter.name)) && !xmlStrcmp(attr->name, Z_STRVAL_P(member)) && match_ns(sxe, (xmlNodePtr) attr, sxe->iter.nsprefix)) { - exists = 1; - break; + if (Z_TYPE_P(member) == IS_LONG) { + int nodendx = 0; + + while (attr && nodendx <= Z_LVAL_P(member)) { + if ((!test || !xmlStrcmp(attr->name, sxe->iter.name)) && match_ns(sxe, (xmlNodePtr) attr, sxe->iter.nsprefix)) { + if (nodendx == Z_LVAL_P(member)) { + exists = 1; + break; + } + nodendx++; + } + attr = attr->next; } + } else { + while (attr) { + if ((!test || !xmlStrcmp(attr->name, sxe->iter.name)) && !xmlStrcmp(attr->name, Z_STRVAL_P(member)) && match_ns(sxe, (xmlNodePtr) attr, sxe->iter.nsprefix)) { + exists = 1; + break; + } - attr = attr->next; + attr = attr->next; + } } } @@ -673,14 +696,6 @@ node = sxe_get_element_by_offset(sxe, Z_LVAL_P(member), node, NULL); } else { - zval tmp_zv; - - if (Z_TYPE_P(member) != IS_STRING) { - tmp_zv = *member; - zval_copy_ctor(&tmp_zv); - member = &tmp_zv; - convert_to_string(member); - } node = node->children; while (node) { xmlNodePtr nnext; @@ -690,9 +705,6 @@ } node = nnext; } - if (member == &tmp_zv) { - zval_dtor(&tmp_zv); - } } if (node) { exists = 1; @@ -700,6 +712,10 @@ } } + if (member == &tmp_zv) { + zval_dtor(&tmp_zv); + } + return exists; } /* }}} */ @@ -732,7 +748,7 @@ zval tmp_zv; int test; - if (Z_TYPE_P(member) != IS_STRING) { + if (Z_TYPE_P(member) != IS_STRING && Z_TYPE_P(member) != IS_LONG) { tmp_zv = *member; zval_copy_ctor(&tmp_zv); member = &tmp_zv; @@ -742,13 +758,24 @@ sxe = php_sxe_fetch_object(object TSRMLS_CC); GET_NODE(sxe, node); + + if (Z_TYPE_P(member) == IS_LONG) { + if (sxe->iter.type != SXE_ITER_ATTRLIST) { + attribs = 0; + elements = 1; + if (sxe->iter.type == SXE_ITER_CHILD) { + node = php_sxe_get_first_node(sxe, node TSRMLS_CC); + } + } + } + if (sxe->iter.type == SXE_ITER_ATTRLIST) { attribs = 1; elements = 0; node = php_sxe_get_first_node(sxe, node TSRMLS_CC); attr = (xmlAttrPtr)node; test = sxe->iter.name != NULL; - } else { + } else if (sxe->iter.type != SXE_ITER_CHILD) { node = php_sxe_get_first_node(sxe, node TSRMLS_CC); attr = node ? node->properties : NULL; test = 0; @@ -756,31 +783,58 @@ if (node) { if (attribs) { - while (attr) { - anext = attr->next; - if ((!test || !xmlStrcmp(attr->name, sxe->iter.name)) && !xmlStrcmp(attr->name, Z_STRVAL_P(member)) && match_ns(sxe, (xmlNodePtr) attr, sxe->iter.nsprefix)) { - xmlUnlinkNode((xmlNodePtr) attr); - php_libxml_node_free_resource((xmlNodePtr) attr TSRMLS_CC); - break; + if (Z_TYPE_P(member) == IS_LONG) { + int nodendx = 0; + + while (attr && nodendx <= Z_LVAL_P(member)) { + if ((!test || !xmlStrcmp(attr->name, sxe->iter.name)) && match_ns(sxe, (xmlNodePtr) attr, sxe->iter.nsprefix)) { + if (nodendx == Z_LVAL_P(member)) { + xmlUnlinkNode((xmlNodePtr) attr); + php_libxml_node_free_resource((xmlNodePtr) attr TSRMLS_CC); + break; + } + nodendx++; + } + attr = attr->next; + } + } else { + while (attr) { + anext = attr->next; + if ((!test || !xmlStrcmp(attr->name, sxe->iter.name)) && !xmlStrcmp(attr->name, Z_STRVAL_P(member)) && match_ns(sxe, (xmlNodePtr) attr, sxe->iter.nsprefix)) { + xmlUnlinkNode((xmlNodePtr) attr); + php_libxml_node_free_resource((xmlNodePtr) attr TSRMLS_CC); + break; + } + attr = anext; } - attr = anext; } } if (elements) { - node = node->children; - while (node) { - nnext = node->next; - - SKIP_TEXT(node); - - if (!xmlStrcmp(node->name, Z_STRVAL_P(member))) { + if (Z_TYPE_P(member) == IS_LONG) { + if (sxe->iter.type == SXE_ITER_CHILD) { + node = php_sxe_get_first_node(sxe, node TSRMLS_CC); + } + node = sxe_get_element_by_offset(sxe, Z_LVAL_P(member), node, NULL); + if (node) { xmlUnlinkNode(node); php_libxml_node_free_resource(node TSRMLS_CC); } + } else { + node = node->children; + while (node) { + nnext = node->next; + + SKIP_TEXT(node); + + if (!xmlStrcmp(node->name, Z_STRVAL_P(member))) { + xmlUnlinkNode(node); + php_libxml_node_free_resource(node TSRMLS_CC); + } next_iter: - node = nnext; + node = nnext; + } } } } @@ -2116,7 +2170,7 @@ { php_info_print_table_start(); php_info_print_table_header(2, "Simplexml support", "enabled"); - php_info_print_table_row(2, "Revision", "$Revision: 1.197 $"); + php_info_print_table_row(2, "Revision", "$Revision: 1.198 $"); php_info_print_table_row(2, "Schema support", #ifdef LIBXML_SCHEMAS_ENABLED "enabled"); http://cvs.php.net/viewcvs.cgi/php-src/ext/simplexml/tests/027.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/simplexml/tests/027.phpt diff -u php-src/ext/simplexml/tests/027.phpt:1.1 php-src/ext/simplexml/tests/027.phpt:1.2 --- php-src/ext/simplexml/tests/027.phpt:1.1 Sat Feb 25 23:41:06 2006 +++ php-src/ext/simplexml/tests/027.phpt Sun Mar 5 14:01:13 2006 @@ -61,7 +61,7 @@ </person> </people> -Warning: main(): Cannot add element person number 3 when only 2 such elements exist in %sext/simplexml/tests/027.php on line %d +Warning: main(): Cannot add element person number 3 when only 2 such elements exist in %s027.php on line %d <people> <person gender="female">Jane </person> @@ -71,4 +71,4 @@ </person> </people> -Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in %sext/simplexml/tests/027.php on line %d +Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in %s027.php on line %d http://cvs.php.net/viewcvs.cgi/php-src/ext/simplexml/tests/bug35785.phpt?r1=1.4&r2=1.5&diff_format=u Index: php-src/ext/simplexml/tests/bug35785.phpt diff -u php-src/ext/simplexml/tests/bug35785.phpt:1.4 php-src/ext/simplexml/tests/bug35785.phpt:1.5 --- php-src/ext/simplexml/tests/bug35785.phpt:1.4 Sun Feb 26 16:40:01 2006 +++ php-src/ext/simplexml/tests/bug35785.phpt Sun Mar 5 14:01:13 2006 @@ -23,4 +23,4 @@ ===FAIL=== int(0) -Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in %sext/simplexml/tests/bug35785.php on line %d +Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in %sbug35785.php on line %d http://cvs.php.net/viewcvs.cgi/php-src/ext/simplexml/tests/030.phpt?view=markup&rev=1.1 Index: php-src/ext/simplexml/tests/030.phpt +++ php-src/ext/simplexml/tests/030.phpt --TEST-- SimpleXML: isset and unset by offset --SKIPIF-- <?php if (!extension_loaded("simplexml")) print "skip"; ?> --FILE-- <?php $xml =<<<EOF <root s:att1="b" att1="a" xmlns:s="urn::test" xmlns:t="urn::test-t"> <child1>test</child1> <child1>test 2</child1> <s:child3 /> </root> EOF; $sxe = simplexml_load_string($xml); echo $sxe->child1[0]."\n"; echo $sxe->child1[1]."\n\n"; var_dump(isset($sxe->child1[1])); unset($sxe->child1[1]); var_dump(isset($sxe->child1[1])); echo "\n"; $atts = $sxe->attributes("urn::test"); var_dump(isset($atts[0])); unset($atts[0]); var_dump(isset($atts[0])); var_dump(isset($atts[TRUE])); ?> ===DONE=== --EXPECT-- test test 2 bool(true) bool(false) bool(true) bool(false) bool(false) ===DONE===
« previous php.cvs (#37116) next »