dmitry Wed Jun 13 13:39:00 2007 UTC Modified files: /php-src/ext/simplexml simplexml.c /php-src/ext/simplexml/tests 027.phpt bug35785.phpt bug41582.phpt Log: Fixed wrong fic for bug #41582
http://cvs.php.net/viewvc.cgi/php-src/ext/simplexml/simplexml.c?r1=1.233&r2=1.234&diff_format=u Index: php-src/ext/simplexml/simplexml.c diff -u php-src/ext/simplexml/simplexml.c:1.233 php-src/ext/simplexml/simplexml.c:1.234 --- php-src/ext/simplexml/simplexml.c:1.233 Tue Jun 5 10:02:02 2007 +++ php-src/ext/simplexml/simplexml.c Wed Jun 13 13:38:59 2007 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: simplexml.c,v 1.233 2007/06/05 10:02:02 tony2001 Exp $ */ +/* $Id: simplexml.c,v 1.234 2007/06/13 13:38:59 dmitry Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -249,18 +249,16 @@ int nodendx = 0; int test = 0; - if (!member) { - return_value = &EG(uninitialized_zval); - return_value->is_ref = 1; - return return_value; - } - sxe = php_sxe_fetch_object(object TSRMLS_CC); - if (Z_TYPE_P(member) == IS_LONG) { + if (!member || Z_TYPE_P(member) == IS_LONG) { if (sxe->iter.type != SXE_ITER_ATTRLIST) { attribs = 0; elements = 1; + } else if (!member) { + /* This happens when the user did: $sxe[]->foo = $value */ + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot create unnamed attribute"); + return NULL; } name = NULL; } else { @@ -288,6 +286,12 @@ node = php_sxe_get_first_node(sxe, node TSRMLS_CC); attr = node ? node->properties : NULL; test = 0; + if (!member && node && node->parent && + node->parent->type == XML_DOCUMENT_NODE) { + /* This happens when the user did: $sxe[]->foo = $value */ + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot create unnamed attribute"); + return NULL; + } } if (node) { @@ -320,13 +324,30 @@ if (!sxe->node) { php_libxml_increment_node_ptr((php_libxml_node_object *)sxe, node, NULL TSRMLS_CC); } - if (Z_TYPE_P(member) == IS_LONG) { + if (!member || Z_TYPE_P(member) == IS_LONG) { + long cnt = 0; + xmlNodePtr mynode = node; + 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 (sxe->iter.type == SXE_ITER_NONE) { + if (member && Z_LVAL_P(member) > 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot add element %s number %ld when only 0 such elements exist", mynode->name, Z_LVAL_P(member)); + } + } else if (member) { + node = sxe_get_element_by_offset(sxe, Z_LVAL_P(member), node, &cnt); + } else { + node = NULL; + } if (node) { _node_as_zval(sxe, node, return_value, SXE_ITER_NONE, NULL, sxe->iter.nsprefix, sxe->iter.isprefix TSRMLS_CC); + } else if (type == BP_VAR_W || type == BP_VAR_RW) { + if (member && cnt < Z_LVAL_P(member)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot add element %s number %ld when only %ld such elements exist", mynode->name, Z_LVAL_P(member), cnt); + } + node = xmlNewTextChild(mynode->parent, mynode->ns, mynode->name, NULL); + _node_as_zval(sxe, node, return_value, SXE_ITER_NONE, NULL, sxe->iter.nsprefix, sxe->iter.isprefix TSRMLS_CC); } } else { #if SXE_ELEMENT_BY_NAME @@ -432,7 +453,6 @@ static void sxe_prop_dim_write(zval *object, zval *member, zval *value, zend_bool elements, zend_bool attribs, xmlNodePtr *pnewnode TSRMLS_DC) { php_sxe_object *sxe; - char *name; xmlNodePtr node; xmlNodePtr newnode = NULL; xmlNodePtr mynode; @@ -446,22 +466,19 @@ long cnt = 0; zval tmp_zv, trim_zv, value_copy; - if (!member) { - /* This happens when the user did: $sxe[] = $value - * and could also be E_PARSE, but we use this only during parsing - * and this is during runtime. - */ - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot create unnamed attribute"); - return; - } - - sxe = php_sxe_fetch_object(object TSRMLS_CC); - if (Z_TYPE_P(member) == IS_LONG) { + if (!member || Z_TYPE_P(member) == IS_LONG) { if (sxe->iter.type != SXE_ITER_ATTRLIST) { attribs = 0; elements = 1; + } else if (!member) { + /* This happens when the user did: $sxe[] = $value + * and could also be E_PARSE, but we use this only during parsing + * and this is during runtime. + */ + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot create unnamed attribute"); + return; } } else { if (Z_TYPE_P(member) != IS_STRING) { @@ -482,8 +499,6 @@ } } - name = Z_STRVAL_P(member); - GET_NODE(sxe, node); if (sxe->iter.type == SXE_ITER_ATTRLIST) { @@ -497,6 +512,15 @@ node = php_sxe_get_first_node(sxe, node TSRMLS_CC); attr = node ? node->properties : NULL; test = 0; + if (!member && node && node->parent && + node->parent->type == XML_DOCUMENT_NODE) { + /* This happens when the user did: $sxe[] = $value + * and could also be E_PARSE, but we use this only during parsing + * and this is during runtime. + */ + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot create unnamed attribute"); + return; + } if (attribs && !node && sxe->iter.type == SXE_ITER_ELEMENT) { node = xmlNewChild(mynode, mynode->ns, sxe->iter.name, NULL); attr = node->properties; @@ -557,7 +581,7 @@ } } else { while (attr) { - if ((!test || !xmlStrcmp(attr->name, sxe->iter.name)) && !xmlStrcmp(attr->name, (xmlChar *)name) && match_ns(sxe, (xmlNodePtr) attr, sxe->iter.nsprefix, sxe->iter.isprefix)) { + if ((!test || !xmlStrcmp(attr->name, sxe->iter.name)) && !xmlStrcmp(attr->name, (xmlChar *)Z_STRVAL_P(member)) && match_ns(sxe, (xmlNodePtr) attr, sxe->iter.nsprefix, sxe->iter.isprefix)) { is_attr = 1; ++counter; break; @@ -569,17 +593,30 @@ } if (elements) { - if (Z_TYPE_P(member) == IS_LONG) { - newnode = sxe_get_element_by_offset(sxe, Z_LVAL_P(member), node, &cnt); - if (newnode) { + if (!member || Z_TYPE_P(member) == IS_LONG) { + if (node->type == XML_ATTRIBUTE_NODE) { + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot create duplicate attribute"); + return; + } + + if (sxe->iter.type == SXE_ITER_NONE) { + newnode = node; ++counter; + if (member && Z_LVAL_P(member) > 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot add element %s number %ld when only 0 such elements exist", mynode->name, Z_LVAL_P(member)); + } + } else if (member) { + newnode = sxe_get_element_by_offset(sxe, Z_LVAL_P(member), node, &cnt); + if (newnode) { + ++counter; + } } } else { node = node->children; while (node) { SKIP_TEXT(node); - if (!xmlStrcmp(node->name, (xmlChar *)name)) { + if (!xmlStrcmp(node->name, (xmlChar *)Z_STRVAL_P(member))) { newnode = node; ++counter; } @@ -605,15 +642,23 @@ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot assign to an array of nodes (duplicate subnodes or attr detected)"); } else if (elements) { if (!node) { - newnode = xmlNewTextChild(mynode, mynode->ns, (xmlChar *)name, value ? (xmlChar *)Z_STRVAL_P(value) : NULL); - } else if (Z_TYPE_P(member) == IS_LONG) { - if (cnt < Z_LVAL_P(member)) { + if (!member || Z_TYPE_P(member) == IS_LONG) { + newnode = xmlNewTextChild(mynode->parent, mynode->ns, mynode->name, value ? (xmlChar *)Z_STRVAL_P(value) : NULL); + } else { + newnode = xmlNewTextChild(mynode, mynode->ns, (xmlChar *)Z_STRVAL_P(member), value ? (xmlChar *)Z_STRVAL_P(value) : NULL); + } + } else if (!member || Z_TYPE_P(member) == IS_LONG) { + if (member && cnt < Z_LVAL_P(member)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot add element %s number %ld when only %ld such elements exist", mynode->name, Z_LVAL_P(member), cnt); } newnode = xmlNewTextChild(mynode->parent, mynode->ns, mynode->name, value ? (xmlChar *)Z_STRVAL_P(value) : NULL); } } else if (attribs) { - newnode = (xmlNodePtr)xmlNewProp(node, (xmlChar *)name, value ? (xmlChar *)Z_STRVAL_P(value) : NULL); + if (Z_TYPE_P(member) == IS_LONG) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot change attribute number %ld when only %d attributes exist", Z_LVAL_P(member), nodendx); + } else { + newnode = (xmlNodePtr)xmlNewProp(node, (xmlChar *)Z_STRVAL_P(member), value ? (xmlChar *)Z_STRVAL_P(value) : NULL); + } } } @@ -648,7 +693,6 @@ } /* }}} */ -#if HELLY_0 static zval** sxe_property_get_adr(zval *object, zval *member TSRMLS_DC) /* {{{ */ { php_sxe_object *sxe; @@ -682,7 +726,6 @@ return &sxe->tmp; } /* }}} */ -#endif /* {{{ sxe_prop_dim_exists() */ @@ -1807,7 +1850,7 @@ sxe_property_write, sxe_dimension_read, sxe_dimension_write, - NULL, + sxe_property_get_adr, sxe_get_value, /* get */ NULL, sxe_property_exists, @@ -2431,7 +2474,7 @@ { php_info_print_table_start(); php_info_print_table_header(2, "Simplexml support", "enabled"); - php_info_print_table_row(2, "Revision", "$Revision: 1.233 $"); + php_info_print_table_row(2, "Revision", "$Revision: 1.234 $"); php_info_print_table_row(2, "Schema support", #ifdef LIBXML_SCHEMAS_ENABLED "enabled"); http://cvs.php.net/viewvc.cgi/php-src/ext/simplexml/tests/027.phpt?r1=1.3&r2=1.4&diff_format=u Index: php-src/ext/simplexml/tests/027.phpt diff -u php-src/ext/simplexml/tests/027.phpt:1.3 php-src/ext/simplexml/tests/027.phpt:1.4 --- php-src/ext/simplexml/tests/027.phpt:1.3 Tue Aug 8 20:52:45 2006 +++ php-src/ext/simplexml/tests/027.phpt Wed Jun 13 13:38:59 2007 @@ -40,7 +40,7 @@ $people->person[2]['gender'] = 'male'; traverse_xml($people); $people->person[3]['gender'] = 'error'; - +traverse_xml($people); ?> ===DONE=== --EXPECTF-- @@ -70,5 +70,14 @@ <person gender="male">Minni-me </person> </people> - -Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in %s027.php on line %d +<people> + <person gender="female">Jane + </person> + <person gender="male">Joe + </person> + <person gender="male">Minni-me + </person> + <person gender="error"> + </person> +</people> +===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/simplexml/tests/bug35785.phpt?r1=1.7&r2=1.8&diff_format=u Index: php-src/ext/simplexml/tests/bug35785.phpt diff -u php-src/ext/simplexml/tests/bug35785.phpt:1.7 php-src/ext/simplexml/tests/bug35785.phpt:1.8 --- php-src/ext/simplexml/tests/bug35785.phpt:1.7 Tue Aug 8 20:52:45 2006 +++ php-src/ext/simplexml/tests/bug35785.phpt Wed Jun 13 13:38:59 2007 @@ -8,13 +8,13 @@ $xml = simplexml_load_string(b"<root></root>"); $xml->bla->posts->name = "FooBar"; echo $xml->asXML(); - -echo "===FAIL===\n"; - $xml = simplexml_load_string(b"<root></root>"); $count = count($xml->bla->posts); var_dump($count); -$xml->bla->posts[++$count]->name = "FooBar"; +$xml->bla->posts[$count]->name = "FooBar"; +echo $xml->asXML(); +$xml = simplexml_load_string(b"<root></root>"); +$xml->bla->posts[]->name = "FooBar"; echo $xml->asXML(); ?> ===DONE=== @@ -22,7 +22,9 @@ --EXPECTF-- <?xml version="1.0"?> <root><bla><posts><name>FooBar</name></posts></bla></root> -===FAIL=== int(0) - -Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in %sbug35785.php on line %d +<?xml version="1.0"?> +<root><bla><posts><name>FooBar</name></posts></bla></root> +<?xml version="1.0"?> +<root><bla><posts><name>FooBar</name></posts></bla></root> +===DONE=== http://cvs.php.net/viewvc.cgi/php-src/ext/simplexml/tests/bug41582.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/simplexml/tests/bug41582.phpt diff -u php-src/ext/simplexml/tests/bug41582.phpt:1.1 php-src/ext/simplexml/tests/bug41582.phpt:1.2 --- php-src/ext/simplexml/tests/bug41582.phpt:1.1 Tue Jun 5 10:02:02 2007 +++ php-src/ext/simplexml/tests/bug41582.phpt Wed Jun 13 13:38:59 2007 @@ -3,13 +3,16 @@ --FILE-- <?php -$xml = new SimpleXMLElement(b'<?xml version="1.0" standalone="yes"?><collection></collection>'); +$xml = new SimpleXMLElement(b'<?xml version="1.0" standalone="yes"?> +<collection></collection>'); -$xml->movie[]->characters->character[0]->name = b'Miss Coder'; +$xml->movie[]->characters->character[0]->name = 'Miss Coder'; -var_dump($xml->asXml()); +echo($xml->asXml()); echo "Done\n"; ?> ---EXPECTF-- -Fatal error: Cannot use object of type stdClass as array in %s on line %d +--EXPECT-- +<?xml version="1.0" standalone="yes"?> +<collection><movie><characters><character><name>Miss Coder</name></character></characters></movie></collection> +Done
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php