Commits

ph...@9ae0c189-cd1f-4510-a509-f4891f5cf20d  committed 543bf41

Modified Files:
dom.c
+ cleaned the domRemoveChild code a bit

t/02parse.t
+ segfault testcase (findnodes remove child)

  • Participants
  • Parent commits d9af518

Comments (0)

Files changed (2)

  **/
 xmlChar*
 domName(xmlNodePtr node) {
-    xmlChar *qname = NULL; 
-    if ( node ) {
-        if (node->ns != NULL && node->ns->prefix != NULL) {
-            xmlChar *tname = xmlStrdup( node->ns->prefix );
-            tname = xmlStrcat( tname , (const xmlChar *) ":" );
-            tname = xmlStrcat( tname , node->name );
-            qname = tname;
-        } 
-        else {
-            qname = xmlStrdup( node->name );
+    const xmlChar *prefix = NULL;
+    const xmlChar *name   = NULL;
+    xmlChar *qname        = NULL; 
+    
+    if ( node == NULL ) {
+        return NULL;
+    }
+
+    switch ( node->type ) {
+    case XML_TEXT_NODE :
+    case XML_COMMENT_NODE :
+    case XML_CDATA_SECTION_NODE :
+    case XML_XINCLUDE_START :
+    case XML_XINCLUDE_END :
+    case XML_ENTITY_REF_NODE :
+    case XML_ENTITY_NODE :
+    case XML_DTD_NODE :
+    case XML_ENTITY_DECL :
+    case XML_DOCUMENT_TYPE_NODE :
+    case XML_PI_NODE :
+    case XML_NOTATION_NODE :
+    case XML_NAMESPACE_DECL :
+        name = node->name;
+        break;
+
+    case XML_DOCUMENT_NODE :
+    case XML_HTML_DOCUMENT_NODE :
+    case XML_DOCB_DOCUMENT_NODE :
+        name = "document";
+        break;
+
+    case XML_DOCUMENT_FRAG_NODE :
+        name = "document_fragment";
+        break;
+
+    case XML_ELEMENT_NODE :
+    case XML_ATTRIBUTE_NODE :
+        if ( node->ns != NULL ) {
+            prefix = node->ns->prefix;
         }
+        name = node->name;
+        break;
+
+    case XML_ELEMENT_DECL :
+        prefix = ((xmlElementPtr) node)->prefix;
+        name = node->name;
+        break;
+
+    case XML_ATTRIBUTE_DECL :
+        prefix = ((xmlAttributePtr) node)->prefix;
+        name = node->name;
+        break;
+    }
+
+    if ( prefix != NULL ) {
+        qname = xmlStrdup( prefix );
+        qname = xmlStrcat( qname , (const xmlChar *) ":" );
+        qname = xmlStrcat( qname , name );
+    } 
+    else {
+        qname = xmlStrdup( node->name );
     }
 
     return qname;
 
 xmlNodePtr
 domRemoveChild( xmlNodePtr self, xmlNodePtr old ) {
-    if ( self  
-         && old 
-	 && old->type != XML_ATTRIBUTE_NODE
-	 && old->type != XML_NAMESPACE_DECL
-         && (self == old->parent)) {
-        domUnlinkNode( old );
+    if ( self == NULL || old == NULL ) {
+        return NULL;
     }
+    if ( old->type == XML_ATTRIBUTE_NODE
+         || old->type == XML_NAMESPACE_DECL ) {
+        return NULL;
+    }
+    if ( self != old->parent ) {
+        /* not a child! */
+        return NULL;
+    }
+
+    domUnlinkNode( old );    
     return old ;
 }
 
             $doc = undef;
             foreach ( @{$bad_strings{$key}} ) {
                eval { $parser->parse_chunk( $_ );};
+               if ( $@ ) { 
+                   # if we won't stop here, we will loose the error :|
+                   last; 
+               }
             }
             if ( $@ ) {
                 ok(1);
                 $parser->parse_chunk("",1); # will cause no harm anymore, but is still needed
                 next;
             }
+           
             eval {    
                 $doc = $parser->parse_chunk("",1);
             };
-            ok( $@ );
+            ok($@);
         }
 
     }