ID: 28584 Updated by: [EMAIL PROTECTED] Reported By: benjcarson at digitaljunkies dot ca -Status: Open +Status: Closed Bug Type: DOM XML related Operating System: Linux PHP Version: 5CVS-2004-05-30 (dev) New Comment:
This bug has been fixed in CVS. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. Thanks for the patch Previous Comments: ------------------------------------------------------------------------ [2004-05-31 00:19:38] benjcarson at digitaljunkies dot ca Description: ------------ DOMText->splitText() does not split text nodes correctly. The node returned from the splitText() includes text from additional DOMText nodes following the one being split. Instead, the returned node should only containg text that was in the original node, following the split offset. Here is a html version of the reproduce code, along with some javascript to demonstrate the splitText() method: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15"> </head> <body> <p id="p" onclick="splitText(this)">text1<i>i</i>text2</p> <script type="text/javascript"> function splitText(node) { text1 = node.firstChild; split = text1.splitText(2); text2 = node.lastChild; str = 'text1: ' + text1.nodeValue + '\n' + 'split: ' + split.nodeValue + '\n' + 'text2: ' + text2.nodeValue; alert(str); } </script> </body></html> It turns out the fix for this is a 1-liner in ext/dom/text.c. I've created a diff available here: http://www.digitaljunkies.ca/~benj/text.c.diff Reproduce code: --------------- #!/usr/bin/php <?php $xml = new DomDocument(); $p = $xml->createElement("p"); $p->insertBefore($text1 = $xml->createTextNode("text1")); $p->insertBefore($i = $xml->createElement("i")); $i->insertBefore($itext = $xml->createTextNode("i")); $p->insertBefore($text2 = $xml->createTextNode("text2")); $split = $text1->splitText(2); echo ("text1: " . $text1->nodeValue . "\n"); echo ("split: " . $split->nodeValue . "\n"); echo ("text2: " . $text2->nodeValue ."\n"); ?> Expected result: ---------------- text1: te split: xt1 text2: text2 Actual result: -------------- text1: te split: xt1text2 text2: text2 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=28584&edit=1
