Anonymous avatar Anonymous committed 42066b5

Modified Files:
LibXML.xs dom.c
[fix] insertBefore and insertAfter with undefined $refNode

Comments (0)

Files changed (2)

         insertPI = 1
     PREINIT:
         xmlNodePtr pinode = NULL;
+        xmlNodePtr delem  = NULL;
         xmlDocPtr real_dom;
         xmlChar * enctarg;
         xmlChar * encdata;
         enctarg = nodeSv2C( name , (xmlNodePtr) real_dom );
         encdata = nodeSv2C( content , (xmlNodePtr) real_dom );
         pinode = xmlNewPI( enctarg, encdata );
+        if ( pinode != NULL ) {
+            warn("got node\n");
+        }
         xmlFree(enctarg);
         xmlFree(encdata);
+        delem = domDocumentElement( real_dom );
         domInsertBefore( (xmlNodePtr)real_dom, 
                          pinode, 
-                         domDocumentElement( real_dom ) );
+                         delem );
 
 SV *
 createProcessingInstruction( dom, name, content=&PL_sv_undef )
         xmlNodePtr pNode, nNode, oNode;
     CODE:
         if ( new != NULL
-             && new != &PL_sv_undef
-             && ref != NULL
-             && ref != &PL_sv_undef ) {
+             && new != &PL_sv_undef ) {
         pNode = getSvNode(self);
         nNode = getSvNode(new);
         oNode = getSvNode(ref);
-
+        
         if ( !(pNode->type == XML_DOCUMENT_NODE
              && nNode->type == XML_ELEMENT_NODE ) 
              && domInsertBefore( pNode, nNode, oNode ) != NULL ) {
         xmlNodePtr pNode, nNode, oNode;
     CODE:
         if ( new != NULL
-             && new != &PL_sv_undef
-             && ref != NULL
-             && ref != &PL_sv_undef ) {
+             && new != &PL_sv_undef ) {
             
         pNode = getSvNode(self);
         nNode = getSvNode(new);
     if ( self == NULL ) {
         return NULL;
     }
+
+    if ( newChild == NULL ) {
+        return newChild;
+    }
   
-    newChild = domIsNotParentOf( newChild, self );
+    if ( domIsNotParentOf( newChild, self ) == NULL ) {
+        return NULL;
+    }
 
     if ( refChild == newChild ) {
         return newChild;
         return NULL;
     }
 
-    if ( newChild != NULL && 
-         self == refChild->parent &&
-         refChild != newChild ) {
-        
-        if( newChild->doc == self->doc ) {
-            domUnbindNode( newChild );
+    if ( self->doc == newChild->doc ){
+        newChild = domUnbindNode( newChild );
+    }
+    else {
+        newChild = domImportNode( self->doc, newChild, 1 );
+    }
+
+    if ( refChild == NULL ) {
+        if ( self->children == NULL ) {
+            newChild = domAppendChild( self, newChild );
         }
         else {
-            domImportNode( self->doc, newChild, 1 );
+            newChild = insert_node_to_nodelist( self->last, newChild, NULL );
         }
-
+    }
+    else if ( self == refChild->parent ) {        
         newChild = insert_node_to_nodelist( refChild, newChild, refChild->next );
     }
     else {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.