diff options
| author | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:37:27 -0400 |
|---|---|---|
| committer | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:37:27 -0400 |
| commit | 2d4e5b09576bb4f0ba716cc82cdf29ea04d9184b (patch) | |
| tree | 41ccc042009cba53e4ce43e727fcba4c1cfbf7f3 /ext/simplexml | |
| parent | d29a4fd2dd3b5d4cf6e80b602544d7b71d794e76 (diff) | |
| download | php-upstream/5.2.2.tar.gz | |
Imported Upstream version 5.2.2upstream/5.2.2
Diffstat (limited to 'ext/simplexml')
| -rw-r--r-- | ext/simplexml/php_simplexml.h | 4 | ||||
| -rwxr-xr-x | ext/simplexml/php_simplexml_exports.h | 4 | ||||
| -rw-r--r-- | ext/simplexml/simplexml.c | 63 | ||||
| -rwxr-xr-x | ext/simplexml/tests/027.phpt | 3 | ||||
| -rwxr-xr-x | ext/simplexml/tests/bug35785.phpt | 7 | ||||
| -rw-r--r-- | ext/simplexml/tests/bug37386.phpt | 25 | ||||
| -rw-r--r-- | ext/simplexml/tests/bug38347.phpt | 2 | ||||
| -rw-r--r-- | ext/simplexml/tests/bug38406.phpt | 33 | ||||
| -rw-r--r-- | ext/simplexml/tests/bug39662.phpt | 37 | ||||
| -rw-r--r-- | ext/simplexml/tests/bug39760.phpt | 40 | ||||
| -rw-r--r-- | ext/simplexml/tests/bug40451.phpt | 22 | ||||
| -rw-r--r-- | ext/simplexml/tests/bug41175.phpt | 16 |
12 files changed, 236 insertions, 20 deletions
diff --git a/ext/simplexml/php_simplexml.h b/ext/simplexml/php_simplexml.h index 4c39360b9..52411cb19 100644 --- a/ext/simplexml/php_simplexml.h +++ b/ext/simplexml/php_simplexml.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_simplexml.h,v 1.20.2.2.2.2 2006/08/07 10:09:52 rrichards Exp $ */ +/* $Id: php_simplexml.h,v 1.20.2.2.2.3 2007/01/01 09:36:06 sebastian Exp $ */ #ifndef PHP_SIMPLEXML_H #define PHP_SIMPLEXML_H diff --git a/ext/simplexml/php_simplexml_exports.h b/ext/simplexml/php_simplexml_exports.h index a9cde7061..20766b910 100755 --- a/ext/simplexml/php_simplexml_exports.h +++ b/ext/simplexml/php_simplexml_exports.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_simplexml_exports.h,v 1.3.2.3 2006/01/01 12:50:13 sniper Exp $ */ +/* $Id: php_simplexml_exports.h,v 1.3.2.3.2.1 2007/01/01 09:36:06 sebastian Exp $ */ #ifndef PHP_SIMPLEXML_EXPORTS_H #define PHP_SIMPLEXML_EXPORTS_H diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index f2b766a34..620d31f7b 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | + | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: simplexml.c,v 1.151.2.22.2.15 2006/09/06 15:31:48 nlopess Exp $ */ +/* $Id: simplexml.c,v 1.151.2.22.2.26 2007/04/24 14:11:28 iliaa Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -56,6 +56,7 @@ static php_sxe_object* php_sxe_object_new(zend_class_entry *ce TSRMLS_DC); static zend_object_value php_sxe_register_object(php_sxe_object * TSRMLS_DC); static xmlNodePtr php_sxe_reset_iterator(php_sxe_object *sxe, int use_data TSRMLS_DC); static xmlNodePtr php_sxe_iterator_fetch(php_sxe_object *sxe, xmlNodePtr node, int use_data TSRMLS_DC); +static zval *sxe_get_value(zval *z TSRMLS_DC); /* {{{ _node_as_zval() */ @@ -137,7 +138,14 @@ static xmlNodePtr sxe_get_element_by_offset(php_sxe_object *sxe, long offset, xm long nodendx = 0; if (sxe->iter.type == SXE_ITER_NONE) { - return NULL; + if (offset == 0) { + if (cnt) { + *cnt = 0; + } + return node; + } else { + return NULL; + } } while (node && nodendx <= offset) { SKIP_TEXT(node) @@ -427,7 +435,8 @@ static void sxe_prop_dim_write(zval *object, zval *member, zval *value, zend_boo int is_attr = 0; int nodendx = 0; int test = 0; - long cnt; + int new_value = 0; + long cnt = 0; zval tmp_zv, trim_zv, value_copy; if (!member) { @@ -504,8 +513,20 @@ static void sxe_prop_dim_write(zval *object, zval *member, zval *value, zend_boo break; case IS_STRING: break; + case IS_OBJECT: + if (Z_OBJCE_P(value) == sxe_class_entry) { + value = sxe_get_value(value TSRMLS_CC); + INIT_PZVAL(value); + new_value = 1; + break; + } + /* break is missing intentionally */ default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "It is not yet possible to assign complex types to %s", attribs ? "attributes" : "properties"); + if (member == &tmp_zv) { + zval_dtor(&tmp_zv); + } + zend_error(E_WARNING, "It is not yet possible to assign complex types to %s", attribs ? "attributes" : "properties"); + return; } } @@ -594,6 +615,9 @@ next_iter: if (value && value == &value_copy) { zval_dtor(value); } + if (new_value) { + zval_ptr_dtor(&value); + } } /* }}} */ @@ -1105,9 +1129,11 @@ SXE_METHOD(xpath) php_libxml_increment_node_ptr((php_libxml_node_object *)sxe, xmlDocGetRootElement((xmlDocPtr) sxe->document->ptr), NULL TSRMLS_CC); } - sxe->xpath->node = sxe->node->node; + nodeptr = php_sxe_get_first_node(sxe, sxe->node->node TSRMLS_CC); - ns = xmlGetNsList((xmlDocPtr) sxe->document->ptr, (xmlNodePtr) sxe->node->node); + sxe->xpath->node = nodeptr; + + ns = xmlGetNsList((xmlDocPtr) sxe->document->ptr, nodeptr); if (ns != NULL) { while (ns[nsnbr] != NULL) { nsnbr++; @@ -1159,6 +1185,7 @@ SXE_METHOD(xpath) xmlXPathFreeObject(retval); } +/* }}} */ /* {{{ proto bool SimpleXMLElement::registerXPathNamespace(string prefix, string ns) Creates a prefix/ns context for the next XPath query */ @@ -1211,7 +1238,7 @@ SXE_METHOD(asXML) node = php_sxe_get_first_node(sxe, node TSRMLS_CC); if (node) { - if (XML_DOCUMENT_NODE == node->parent->type) { + if (node->parent && (XML_DOCUMENT_NODE == node->parent->type)) { int bytes; bytes = xmlSaveFile(filename, (xmlDocPtr) sxe->document->ptr); if (bytes == -1) { @@ -1240,7 +1267,7 @@ SXE_METHOD(asXML) node = php_sxe_get_first_node(sxe, node TSRMLS_CC); if (node) { - if (XML_DOCUMENT_NODE == node->parent->type) { + if (node->parent && (XML_DOCUMENT_NODE == node->parent->type)) { xmlDocDumpMemory((xmlDocPtr) sxe->document->ptr, &strval, &strval_len); RETVAL_STRINGL((char *)strval, strval_len, 1); xmlFree(strval); @@ -1515,8 +1542,8 @@ SXE_METHOD(addAttribute) return; } - if (qname_len == 0 || value_len == 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute name and value are required"); + if (qname_len == 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute name is required"); return; } @@ -1525,7 +1552,7 @@ SXE_METHOD(addAttribute) node = php_sxe_get_first_node(sxe, node TSRMLS_CC); - if (node->type != XML_ELEMENT_NODE) { + if (node && node->type != XML_ELEMENT_NODE) { node = node->parent; } @@ -1760,6 +1787,16 @@ sxe_object_clone(void *object, void **clone_ptr TSRMLS_DC) clone->document->refcount++; docp = clone->document->ptr; } + + clone->iter.isprefix = sxe->iter.isprefix; + if (sxe->iter.name != NULL) { + clone->iter.name = xmlStrdup((xmlChar *)sxe->iter.name); + } + if (sxe->iter.nsprefix != NULL) { + clone->iter.nsprefix = xmlStrdup((xmlChar *)sxe->iter.nsprefix); + } + clone->iter.type = sxe->iter.type; + if (sxe->node) { nodep = xmlDocCopyNode(sxe->node->node, docp, 1); } @@ -2331,7 +2368,7 @@ PHP_MINFO_FUNCTION(simplexml) { php_info_print_table_start(); php_info_print_table_header(2, "Simplexml support", "enabled"); - php_info_print_table_row(2, "Revision", "$Revision: 1.151.2.22.2.15 $"); + php_info_print_table_row(2, "Revision", "$Revision: 1.151.2.22.2.26 $"); php_info_print_table_row(2, "Schema support", #ifdef LIBXML_SCHEMAS_ENABLED "enabled"); diff --git a/ext/simplexml/tests/027.phpt b/ext/simplexml/tests/027.phpt index f32786c7c..105f99066 100755 --- a/ext/simplexml/tests/027.phpt +++ b/ext/simplexml/tests/027.phpt @@ -71,4 +71,5 @@ Warning: main(): Cannot add element person number 3 when only 2 such elements ex </person> </people> -Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in %s027.php on line %d +Notice: Indirect modification of overloaded element of SimpleXMLElement has no effect in %s027.php on line %d +===DONE=== diff --git a/ext/simplexml/tests/bug35785.phpt b/ext/simplexml/tests/bug35785.phpt index 096ab7a68..4156a7c9f 100755 --- a/ext/simplexml/tests/bug35785.phpt +++ b/ext/simplexml/tests/bug35785.phpt @@ -25,4 +25,9 @@ echo $xml->asXML(); ===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 +Notice: Indirect modification of overloaded element of SimpleXMLElement has no effect in %sbug35785.php on line %d + +Strict Standards: Creating default object from empty value in %sbug35785.php on line %d +<?xml version="1.0"?> +<root><bla><posts/></bla></root> +===DONE=== diff --git a/ext/simplexml/tests/bug37386.phpt b/ext/simplexml/tests/bug37386.phpt new file mode 100644 index 000000000..cf8690613 --- /dev/null +++ b/ext/simplexml/tests/bug37386.phpt @@ -0,0 +1,25 @@ +--TEST-- +Bug #39760 (autocreating element doesn't assign value to first node) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip simplexml extension is not loaded"; ?> +--FILE-- +<?php + +$sx1 = new SimpleXMLElement((binary)"<root />"); + +$sx1->node[0] = 'node1'; +$sx1->node[1] = 'node2'; + +print $sx1->asXML()."\n"; +$node = $sx1->node[0]; +$node[0] = 'New Value'; + +print $sx1->asXML(); + +?> +--EXPECTF-- +<?xml version="1.0"?> +<root><node>node1</node><node>node2</node></root> + +<?xml version="1.0"?> +<root><node>New Value</node><node>node2</node></root> diff --git a/ext/simplexml/tests/bug38347.phpt b/ext/simplexml/tests/bug38347.phpt index c25fccea2..0ea7b5d2f 100644 --- a/ext/simplexml/tests/bug38347.phpt +++ b/ext/simplexml/tests/bug38347.phpt @@ -24,5 +24,5 @@ SimpleXMLElement Object ( ) -Warning: iterate(): Node no longer exists in %s on line %d +Warning: Invalid argument supplied for foreach() in %sbug38347.php on line 6 Done diff --git a/ext/simplexml/tests/bug38406.phpt b/ext/simplexml/tests/bug38406.phpt new file mode 100644 index 000000000..f439e33e5 --- /dev/null +++ b/ext/simplexml/tests/bug38406.phpt @@ -0,0 +1,33 @@ +--TEST-- +Bug #38406 (crash when assigning objects to SimpleXML attributes) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php + +$item = new SimpleXMLElement(b'<something />'); +$item->attribute = b'something'; +var_dump($item->attribute); + +$item->otherAttribute = $item->attribute; +var_dump($item->otherAttribute); + +$a = array(); +$item->$a = new stdclass; + +echo "Done\n"; +?> +--EXPECTF-- +object(SimpleXMLElement)#%d (1) { + [0]=> + string(9) "something" +} +object(SimpleXMLElement)#%d (1) { + [0]=> + string(9) "something" +} + +Notice: Array to string conversion in %s on line %d + +Warning: It is not yet possible to assign complex types to properties in %s on line %d +Done diff --git a/ext/simplexml/tests/bug39662.phpt b/ext/simplexml/tests/bug39662.phpt new file mode 100644 index 000000000..ae15f2ef0 --- /dev/null +++ b/ext/simplexml/tests/bug39662.phpt @@ -0,0 +1,37 @@ +--TEST-- +Bug #39662 (Segfault when calling asXML() of a cloned SimpleXMLElement) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip simplexml extension is not loaded"; ?> +--FILE-- +<?php + +$xml = '<?xml version="1.0" encoding="utf-8" ?> +<test> + +</test>'; + +$root = simplexml_load_string($xml); +$clone = clone $root; +var_dump($root); +var_dump($clone); +var_dump($clone->asXML()); + +echo "Done\n"; +?> +--EXPECTF-- +object(SimpleXMLElement)#%d (1) { + [0]=> + string(2) " + +" +} +object(SimpleXMLElement)#%d (1) { + [0]=> + string(2) " + +" +} +string(15) "<test> + +</test>" +Done diff --git a/ext/simplexml/tests/bug39760.phpt b/ext/simplexml/tests/bug39760.phpt new file mode 100644 index 000000000..e781765fa --- /dev/null +++ b/ext/simplexml/tests/bug39760.phpt @@ -0,0 +1,40 @@ +--TEST-- +Bug #39760 (cloning fails on nested SimpleXML-Object) +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip simplexml extension is not loaded"; ?> +--FILE-- +<?php + +$xml = '<?xml version="1.0" ?> +<test> + <level1> + <level2a>text1</level2a> + <level2b>text2</level2b> + </level1> +</test>'; +$test = simplexml_load_string($xml); + +var_dump($test->level1->level2a); + +$test2 = clone $test; +var_dump($test2->level1->level2a); + +$test3 = clone $test->level1->level2a; +var_dump($test3); + +echo "Done\n"; +?> +--EXPECTF-- +object(SimpleXMLElement)#%d (1) { + [0]=> + string(5) "text1" +} +object(SimpleXMLElement)#%d (1) { + [0]=> + string(5) "text1" +} +object(SimpleXMLElement)#%d (1) { + [0]=> + string(5) "text1" +} +Done diff --git a/ext/simplexml/tests/bug40451.phpt b/ext/simplexml/tests/bug40451.phpt new file mode 100644 index 000000000..1a499a731 --- /dev/null +++ b/ext/simplexml/tests/bug40451.phpt @@ -0,0 +1,22 @@ +--TEST-- +Bug #40451 (addAttribute() may crash when used with non-existent child node) +--FILE-- +<?php + +$string = <<<XML +<?xml version="1.0"?> + <Host enable="true"> + <Name>host.server.com</Name> + </Host> +XML; + +$xml = simplexml_load_string($string); + +$add = $xml->addChild('Host'); +$add->Host->addAttribute('enable', 'true'); + +echo "Done\n"; +?> +--EXPECTF-- +Warning: SimpleXMLElement::addAttribute(): Unable to locate parent Element in %s on line %d +Done diff --git a/ext/simplexml/tests/bug41175.phpt b/ext/simplexml/tests/bug41175.phpt new file mode 100644 index 000000000..51181d29c --- /dev/null +++ b/ext/simplexml/tests/bug41175.phpt @@ -0,0 +1,16 @@ +--TEST-- +Bug #41175 (addAttribute() fails to add an attribute with an empty value) +--FILE-- +<?php + +$xml = new SimpleXmlElement("<img></img>"); +$xml->addAttribute("src", "foo"); +$xml->addAttribute("alt", ""); +echo $xml->asXML(); + +echo "Done\n"; +?> +--EXPECT-- +<?xml version="1.0"?> +<img src="foo" alt=""/> +Done
\ No newline at end of file |
