Commits

Anonymous committed c8d774e

Modified Files:
Changes
+ version notes

LibXML.xs
+ fixed validating parser bug

t/02parse.t
+ 1st validating parser test

  • Participants
  • Parent commits 6fa11df

Comments (0)

Files changed (3)

    - fixed default iterator of XML::LibXML::Iterator
    - interface for raw libxml2 DOM building functions 
      (currently just addChild(), others will follow)
+   - fixed bad behaviour of the validating parser
    - fixed memory leak in push parser code
    - fixed namespace handling if nodes are imported to a new DOM.
    - fixed segmentation fault during validation under libxml2 2.4.25
     va_list args;
     SV * sv;
     /* xmlParserCtxtPtr context = (xmlParserCtxtPtr) ctxt; */
-
     sv = NEWSV(0,512);
 
     va_start(args, msg);
         SV * RETVAL  = NULL; /* dummy for the stupid macro */
 
         LibXML_init_error();
+        xmlSetGenericErrorFunc( NULL , 
+                                (xmlGenericErrorFunc)LibXML_error_handler);
 
         item = hv_fetch( real_obj, "XML_LIBXML_VALIDATION", 21, 0 );
         if ( item != NULL && SvTRUE(*item) ) {  
             xmlSetExternalEntityLoader( (xmlExternalEntityLoader)LibXML_load_external_entity );
         }
         else {
-            LibXML_old_ext_ent_loader =  NULL; 
+            /* LibXML_old_ext_ent_loader =  NULL; */
         }
     }
 
         RETVAL
 
 SV*
-_parse_string(self, string, directory = NULL)
+_parse_string(self, string, dir = &PL_sv_undef)
         SV * self
         SV * string
-        char * directory
+        SV * dir
     PREINIT:
         xmlParserCtxtPtr ctxt = NULL;
-        STRLEN len;
-        char * ptr;
+        STRLEN len = 0;
+        xmlChar * ptr = NULL;
         int well_formed;
         int valid;
         int ret;
         HV* real_obj = (HV *)SvRV(self);
         SV** item    = NULL;
         int recover ;
+        xmlChar * directory = NULL;
     CODE:
-        ptr = SvPV(string, len);
+        ptr = SvPV(string, len);        
         if (len == 0) {
             croak("Empty string");
         }
-
+  
         LibXML_init_parser(self);
         ctxt = xmlCreateMemoryParserCtxt(ptr, len);
         if (ctxt == NULL) {
             croak("Couldn't create memory parser context: %s", strerror(errno));
         }
-        ctxt->directory = directory;
+
+        directory = Sv2C( dir, NULL );
 
         xs_warn( "context created\n");
 
+        if ( directory != NULL ) {
+            ctxt->directory = directory;
+        }
+
         ctxt->_private = (void*)self;
         
         xs_warn( "context initialized \n");        
+
         ret = xmlParseDocument(ctxt);
-
         xs_warn( "document parsed \n");
-
         ctxt->directory = NULL;
 
         well_formed = ctxt->wellFormed;
             XSRETURN_UNDEF;
         }
 
+  
         if ( directory == NULL ) {
             STRLEN len;
-            SV * newURI = sv_2mortal(newSVpvf("unknown-%12.12d", (void*)real_doc));
+            SV * newURI;
+
+            newURI = sv_2mortal(newSVpvf("unknown-%12.12d", (void*)real_doc));
             real_doc->URL = xmlStrdup((const xmlChar*)SvPV(newURI, len));
         } else {
             real_doc->URL = xmlStrdup((const xmlChar*)directory);
         recover = ( item != NULL && SvTRUE(*item) ) ? 1 : 0;
         if ( ( !well_formed && !recover )
                || (xmlDoValidityCheckingDefaultValue
-                    && !valid && !recover 
-                    && (real_doc->intSubset || real_doc->extSubset) ) ) {
+                    && valid == 0 && recover == 0 ) ) {
             xmlFreeDoc(real_doc);
             RETVAL = &PL_sv_undef;    
             croak("%s",SvPV(LibXML_error, len));
             XSRETURN_UNDEF;
         }
         else if (xmlDoValidityCheckingDefaultValue
-                 && (real_doc->intSubset || real_doc->extSubset) 
                  && recover == 0 ) {
             LibXML_croak_error();
         }
         if (  ( !well_formed && !recover )
                || (xmlDoValidityCheckingDefaultValue
                    && !recover 
-                   && (!valid
-                       || SvCUR(LibXML_error) > 0 )
-                   && (real_doc->intSubset
-                       || real_doc->extSubset) )  ) {
+                   && !valid ) ) {
             xmlFreeDoc(real_doc);
             croak("'%s'",SvPV(LibXML_error, len));
             XSRETURN_UNDEF;
                 xmlUnlinkNode( (xmlNodePtr)intSubset );
         }
 
-        LibXML_init_error();
+        /* LibXML_init_error(); */
 
         if ( format <= 0 ) {
             xs_warn( "use no formated toString!" );
         }
 
         xmlSaveNoEmptyTags = oldTagFlag;
-
-        sv_2mortal( LibXML_error );
+/*        sv_2mortal( LibXML_error );
         LibXML_croak_error();
-
+*/
     	if (result == NULL) {
 	        xs_warn("Failed to convert doc to string");           
             XSRETURN_UNDEF;
             }
             xmlXPathFreeObject(found);
         }
-        else {
-            LibXML_croak_error();
-        }
 
 void
 _findnodes( pnode, perl_xpath )
             }
             xmlXPathFreeNodeSet( nodelist );
         }
-        else {
-            LibXML_croak_error();
-        }
 
 void
 getNamespaces( pnode )
 use Test;
 use IO::File;
 
-BEGIN { plan tests => 457 };
+BEGIN { plan tests => 460 };
 use XML::LibXML;
 use XML::LibXML::Common qw(:libxml);
 use XML::LibXML::SAX;
     }
 }
 
+{
+    print "# 6 VALIDATING PARSER\n";
+
+    my %badstrings = (
+                    SIMPLE => '<?xml version="1.0"?>'."\n<A/>\n",
+                  );
+    my $parser = XML::LibXML->new;
+    $parser->validation(1);
+    my $doc;
+    eval { $doc = $parser->parse_string($badstrings{SIMPLE}); };
+    ok( $@ );
+    my $ql;
+}
+
 sub tsub {
     my $doc = shift;
 
 
     return $th->{d};
 }
+
+sub tsub2 {
+    my ($doc,$query)=($_[0],@{$_[1]});
+#    return [ $doc->findnodes($query) ];
+    return [ $doc->findnodes(encodeToUTF8('iso-8859-1',$query)) ];
+}