php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15966 replace_node incorrect
Submitted: 2002-03-08 20:39 UTC Modified: 2002-08-14 12:54 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: bigredlinux at yahoo dot com Assigned:
Status: Closed Package: DOM XML related
PHP Version: 4.1.2 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bigredlinux at yahoo dot com
New email:
PHP Version: OS:

 

 [2002-03-08 20:39 UTC] bigredlinux at yahoo dot com
When replace_node is used, if the new node being inserted already exists in the xml document, it is to be first removed.  Thus, the following lines in the C code are incorrect...

if (NULL == (new_repnode = xmlCopyNode(repnode, 1))) {
        php_error(E_WARNING, "%s(): unable to clone node", get_active_function_name(TSRMLS_C));
        RETURN_FALSE;
    }

repnode = xmlReplaceNode(nodep, new_repnode);

This code is making a copy of the new node, and hence when the libxml2 function xmlReplaceNode is run, it does not remove the node already existing in the document.  The call to xmlReplaceNode should be the repnode, not the new_repnode.  As a matter of fact, I see no need to even attempt to clone the node, unless it is to check that it is a true node.

Thoughts?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-18 02:03 UTC] steinm@php.net
xmlReplaceNode replaces the node in the first argument,
which is the current node, by the new copied node.
Sounds reasonable to me. It returns the old node which we
don't care about. You should have a reference to the old
node anyway. Ok, the old node isn't deleted only unlinked
but that is the only way to go since the corresponding
PHP variable can't be deleted at this time.

Making a copy is actually a point to discuss. But currently
it needs to be done because if the same libxml node is returned you will probably end up with two PHP variables
pointing to the same libxml node. If one is deleted the
other one will lose its libxml node as well. I guess this
could be solved with references but I don't know how yet.
 [2002-04-27 04:39 UTC] dan at mojavelinux dot com
Now the implementation is even worse.  Here is the current state.  The new node now replaces the old node and returns the new node, but it DOES NOT update the pointer to the new node, so now you just lost your pointer in the document.  This is just not acceptable because in xml the pointer is probably the single most important concept.  If you loose your pointer you don't know where you are anymore and you can't get back there unless you know what the document looks like.  I think that it is really necessary to update this pointer so that the new node that you pass in is still a reference to the new location.
 [2002-04-27 04:41 UTC] dan at mojavelinux dot com
sorry, I meant to say it returns the old node, as it should according to spec, that is fine, but not the point.
 [2002-08-14 12:54 UTC] chregu@php.net
Fixed in CVS

Dan, could you please check, if it's alright now?

chregu
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 13:01:31 2024 UTC