cvs: php-src /ext/simplexml simplexml.c /ext/simplexml/tests bug37386.phpt
| From: | Rob Richards | Date: | Mon, 26 Mar 2007 20:16:16 +0000 |
| Subject: | cvs: php-src /ext/simplexml simplexml.c /ext/simplexml/tests bug37386.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-43645@lists.php.net to get a copy of this message | ||
rrichards Mon Mar 26 20:16:16 2007 UTC
Modified files:
/php-src/ext/simplexml simplexml.c
/php-src/ext/simplexml/tests bug37386.phpt
Log:
MFB: fix bug #37386 (autocreating element doesn't assign value to first node)
all single SimpleXMLElements are addressable using offset 0
use correct node for xpath context node
add test
http://cvs.php.net/viewvc.cgi/php-src/ext/simplexml/simplexml.c?r1=1.230&r2=1.231&diff_format=u
Index: php-src/ext/simplexml/simplexml.c
diff -u php-src/ext/simplexml/simplexml.c:1.230 php-src/ext/simplexml/simplexml.c:1.231
--- php-src/ext/simplexml/simplexml.c:1.230 Tue Feb 20 14:04:59 2007
+++ php-src/ext/simplexml/simplexml.c Mon Mar 26 20:16:15 2007
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: simplexml.c,v 1.230 2007/02/20 14:04:59 tony2001 Exp $ */
+/* $Id: simplexml.c,v 1.231 2007/03/26 20:16:15 rrichards Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -138,7 +138,14 @@
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)
@@ -430,7 +437,7 @@
int nodendx = 0;
int test = 0;
int new_value = 0;
- long cnt;
+ long cnt = 0;
zval tmp_zv, trim_zv, value_copy;
if (!member) {
@@ -1158,9 +1165,11 @@
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);
+
+ sxe->xpath->node = nodeptr;
- ns = xmlGetNsList((xmlDocPtr) sxe->document->ptr, (xmlNodePtr) sxe->node->node);
+ ns = xmlGetNsList((xmlDocPtr) sxe->document->ptr, nodeptr);
if (ns != NULL) {
while (ns[nsnbr] != NULL) {
nsnbr++;
@@ -2416,7 +2425,7 @@
{
php_info_print_table_start();
php_info_print_table_header(2, "Simplexml support", "enabled");
- php_info_print_table_row(2, "Revision", "$Revision: 1.230 $");
+ php_info_print_table_row(2, "Revision", "$Revision: 1.231 $");
php_info_print_table_row(2, "Schema support",
#ifdef LIBXML_SCHEMAS_ENABLED
"enabled");
http://cvs.php.net/viewvc.cgi/php-src/ext/simplexml/tests/bug37386.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/simplexml/tests/bug37386.phpt
diff -u /dev/null php-src/ext/simplexml/tests/bug37386.phpt:1.2
--- /dev/null Mon Mar 26 20:16:16 2007
+++ php-src/ext/simplexml/tests/bug37386.phpt Mon Mar 26 20:16:16 2007
@@ -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>