From: benjcarson at digitaljunkies dot ca Operating system: Linux PHP version: 5CVS-2004-06-10 (dev) PHP Bug Type: DOM XML related Bug description: appendChild() and insertBefore() unset DOMText node arguments (includes patch)
Description: ------------ If a DOMText node is added to a node using appendChild() or insertBefore(), the node is destroyed (i.e. the parameter's properties are cleared) and a new node is returned instead. In addition, when a text node is inserted it is collapsed with adjacent text nodes. This behaviour is inconsistent with other DOM implementations (e.g. Mozilla, gdome). It means that code like this: $p->appendChild($textNode); will unset all of $textNode's properties. Here is an html version of the reproduce code, for an example of what your browser does: http://www.digitaljunkies.ca/~benj/dom_insert_demo.php I've tried to fix this and I've rolled a patch available at: http://www.digitaljunkies.ca/~benj/node.c.diff Basically what I've done is remove any special handling of text nodes. In appendChild() I also manually add the child to the parent's children list. This is because xmlAddChild collapses adjacent text nodes. (I figure that if adjacent text nodes need to be collapsed, users can use DomDocument::normalize().) In looking at the code, there may be a similar problem with attribute nodes, but since I'm not as familliar with manipulating them, I'm not sure what the desired behaviour should be. Please indicate if there are any problems with the patch. Thanks. Reproduce code: --------------- #!/usr/bin/php <?php $xml = new DomDocument(); $p = $xml->createElement("p"); $p->appendChild($t1 = $xml->createTextNode(" t1 ")); $p->appendChild($b = $xml->createElement("b")); $b->appendChild($xml->createTextNode("X")); $p->appendChild($t2 = $xml->createTextNode("")); $ret = $p->appendChild($t1); var_dump($t1->nodeName); var_dump($ret->nodeName); var_dump( $t1 === $ret ); var_dump( $p->lastChild->nodeValue ); ?> Expected result: ---------------- string(5) "#text" string(5) "#text" bool(true) string(4) " t1 " Actual result: -------------- NULL string(5) "#text" bool(false) string(8) " t2 t1 " -- Edit bug report at http://bugs.php.net/?id=28721&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=28721&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=28721&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=28721&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=28721&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=28721&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=28721&r=needscript Try newer version: http://bugs.php.net/fix.php?id=28721&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=28721&r=support Expected behavior: http://bugs.php.net/fix.php?id=28721&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=28721&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=28721&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=28721&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28721&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=28721&r=dst IIS Stability: http://bugs.php.net/fix.php?id=28721&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=28721&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=28721&r=float