ID: 28721 User updated by: benjcarson at digitaljunkies dot ca Reported By: benjcarson at digitaljunkies dot ca Status: Open Bug Type: DOM XML related Operating System: Linux PHP Version: 5CVS-2004-06-10 (dev) New Comment:
There was a bug with insertBefore() in the patch. If you downloaded the patch prior to this post, please download it again. Previous Comments: ------------------------------------------------------------------------ [2004-06-10 07:12:43] benjcarson at digitaljunkies dot ca 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 this bug report at http://bugs.php.net/?id=28721&edit=1