Commits

Anonymous committed ae6db08

perl-libxml-sax.c
[fix] attribute / namespace handling
[fix] jclark attribute names work now correctly

t/02parse.t
+ very simple direct sax test.

  • Participants
  • Parent commits fb39329

Comments (0)

Files changed (2)

File perl-libxml-sax.c

 PmmGenNsName( const xmlChar * name, xmlChar * nsURI ) {
     int namelen = 0;
     int urilen = 0;
-    xmlChar * retval;
+    xmlChar * retval = NULL;
     namelen = xmlStrlen( name );
     if ( nsURI != NULL ) {
         urilen = xmlStrlen( nsURI );
     }
-    retval = (xmlChar *)xmlMalloc( (namelen + urilen + 2) * sizeof(xmlChar));
-    *retval = 0;
 
-    xmlStrncat( retval, "{",1 );
+
+    retval =xmlStrncat( retval, "{",1 );
     if ( nsURI != NULL ) {
-        xmlStrncat( retval, nsURI, urilen );
+        retval =xmlStrncat( retval, nsURI, urilen );
     } 
-    xmlStrncat( retval, "}",1 );
-    xmlStrncat( retval, name, namelen );
+    retval = xmlStrncat( retval, "}",1 );
+    retval = xmlStrncat( retval, name, namelen );
     return retval;
 }
 
 
     if ( attr != NULL ) {
         while ( *ta != NULL ) {
-            if ( PmmDetectNamespaceDecl( *ta ) ) {
-                name = *ta; ta++;
-                value = *ta; ta++;
-                PmmAddNamespace(sax, name, value);                
-            }
-            else {
-                ta++;ta++;
+            name = *ta; ta++;
+            value = *ta; ta++;
+            if (PmmDetectNamespaceDecl(name)) {
+                PmmAddNamespace(sax, name, value);  
             }
         }
-        
+
         ta = attr;
 
         while ( *ta != NULL ) {
  
     dTHX;
     dSP;
-
     
     ENTER;
     SAVETMPS;
 
     count = perl_call_pv( "XML::LibXML::_SAXParser::start_element", 0 );
 
+    SPAGAIN ;
+
     FREETMPS ;
     LEAVE ;
 
 use Test;
 use IO::File;
 
-BEGIN { plan tests => 41 };
+BEGIN { plan tests => 42 };
 use XML::LibXML;
 
 ##
     my $handler = XML::LibXML::SAX::Builder->new();
     my $generator = XML::LibXML::SAX->new( Handler=>$handler );
 
+
+    my $string1  = q{<bar>foo</bar>};
+
+    $doc = $generator->parse_string( $string1 );
+    ok( $doc );
+
     my $string  = q{<bar foo="bar">foo</bar>};
 
     $doc = $generator->parse_string( $string );
     my $root = $doc->documentElement;
     my @attrs = $root->attributes;
     ok( scalar @attrs );
-    ok( $attrs[0]->nodeType, XML_NAMESPACE_DECL );
+    if ( scalar @attrs ) {
+        ok( $attrs[0]->nodeType, XML_NAMESPACE_DECL );
+    }
+    else {
+        ok(0);
+    }
 
     $doc = $generator->parse_uri( "example/test.xml" );