cvs: php-src /ext/dom text.c /ext/dom/tests bug41374.phpt

From: Date: Mon, 14 May 2007 11:44:50 +0000
Subject: cvs: php-src /ext/dom text.c /ext/dom/tests bug41374.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-44292@lists.php.net to get a copy of this message
rrichards Mon May 14 11:44:50 2007 UTC Modified files: /php-src/ext/dom text.c /php-src/ext/dom/tests bug41374.phpt Log: Fixed bug #41374 (wholetext concats values of wrong nodes). add test http://cvs.php.net/viewvc.cgi/php-src/ext/dom/text.c?r1=1.31&r2=1.32&diff_format=u Index: php-src/ext/dom/text.c diff -u php-src/ext/dom/text.c:1.31 php-src/ext/dom/text.c:1.32 --- php-src/ext/dom/text.c:1.31 Mon Jan 1 09:29:23 2007 +++ php-src/ext/dom/text.c Mon May 14 11:44:50 2007 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: text.c,v 1.31 2007/01/01 09:29:23 sebastian Exp $ */ +/* $Id: text.c,v 1.32 2007/05/14 11:44:50 rrichards Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -87,7 +87,7 @@ int dom_text_whole_text_read(dom_object *obj, zval **retval TSRMLS_DC) { xmlNodePtr node; - xmlChar *wholetext; + xmlChar *wholetext = NULL; node = dom_object_get_node(obj); @@ -96,9 +96,23 @@ return FAILURE; } + /* Find starting text node */ + while (node->prev && ((node->prev->type == XML_TEXT_NODE) || (node->prev->type == XML_CDATA_SECTION_NODE))) { + node = node->prev; + } + + /* concatenate all adjacent text and cdata nodes */ + while (node && ((node->type == XML_TEXT_NODE) || (node->type == XML_CDATA_SECTION_NODE))) { + wholetext = xmlStrcat(wholetext, node->content); + node = node->next; + } + ALLOC_ZVAL(*retval); - wholetext = xmlNodeListGetString(node->doc, node, 1); - ZVAL_XML_STRING(*retval, wholetext, ZSTR_DUPLICATE); + if (wholetext != NULL) { + ZVAL_XML_STRING(*retval, wholetext, ZSTR_DUPLICATE); + } else { + ZVAL_EMPTY_STRING(*retval); + } xmlFree(wholetext); http://cvs.php.net/viewvc.cgi/php-src/ext/dom/tests/bug41374.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/dom/tests/bug41374.phpt diff -u /dev/null php-src/ext/dom/tests/bug41374.phpt:1.2 --- /dev/null Mon May 14 11:44:50 2007 +++ php-src/ext/dom/tests/bug41374.phpt Mon May 14 11:44:50 2007 @@ -0,0 +1,32 @@ +--TEST-- +Bug # 41374: (wholetext concats values of wrong nodes) +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +$xml = (binary)<<<EOXML +<?xml version="1.0" encoding="ISO-8859-1" ?> +<root>foo<child />baz</root> +EOXML; + +$doc = new DOMDocument(); +$doc->loadXML($xml); + +$root = $doc->documentElement; +$foo = $root->firstChild; + +var_dump($foo->wholeText == "foo"); + +$bar = $root->insertBefore($doc->createTextNode("bar"), $foo->nextSibling); + +var_dump($foo->wholeText == "foobar"); +var_dump($foo->wholeText == $bar->wholeText); +$baz = $bar->nextSibling->nextSibling; + +var_dump($baz->wholeText === $foo->wholeText); +?> +--EXPECT-- +bool(true) +bool(true) +bool(true) +bool(false)

« previous php.cvs (#44292) next »