From: benjcarson at digitaljunkies dot ca Operating system: Linux PHP version: 5CVS-2004-05-30 (dev) PHP Bug Type: DOM XML related Bug description: DOMText::splitText() does not split text properly (includes patch)
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 bug report at http://bugs.php.net/?id=28584&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=28584&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=28584&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=28584&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=28584&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=28584&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=28584&r=needscript Try newer version: http://bugs.php.net/fix.php?id=28584&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=28584&r=support Expected behavior: http://bugs.php.net/fix.php?id=28584&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=28584&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=28584&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=28584&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28584&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=28584&r=dst IIS Stability: http://bugs.php.net/fix.php?id=28584&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=28584&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=28584&r=float
