Commits

Anonymous committed 6a03eda

Modified Files:
LibXML.xs
+ croaks now if empty strings or streams are processed.

perl-libxml-mm.c
o fixes a gcc warning :)

t/02parsestring.t
+ empty string tests

Comments (0)

Files changed (3)

             xmlFreeParserCtxt(ctxt);
         }
     }
+    else {
+        croak( "Empty Stream" );
+    }
     
     if (!well_formed || (xmlDoValidityCheckingDefaultValue && !valid && (doc->intSubset || doc->extSubset) )) {
         xmlFreeDoc(doc);
             htmlFreeParserCtxt(ctxt);
         }
     }
+    else {
+        croak( "Empty Stream" );
+    }
     
     if (!well_formed) {
         xmlFreeDoc(doc);
 
         LibXML_init_parser(self);
         real_dom = LibXML_parse_stream(self, fh, directory);
-
+        
         sv_2mortal(LibXML_error);
         
         if (real_dom == NULL) {
         xmlNodePtr fragment= NULL;
         ProxyObject *ret=NULL;
         xmlNodePtr rv_end = NULL;
+        char * ptr;
+        STRLEN len;
     CODE:
         if ( encoding == NULL ) encoding = "UTF-8";
-
+        ptr = SvPV(svchunk, len);
+        if (len == 0) {
+            croak("Empty string");
+        }
+    
         chunk = Sv2C(svchunk, encoding);
 
         if ( chunk != NULL ) {
 #ifdef HAVE_UTF8
         if ( SvUTF8(string) ) {
 #endif
-        realstring = Sv2C(string,"UTF8" );
-        tstr =  domDecodeString( encoding, realstring );
-        RETVAL = C2Sv(tstr,(xmlChar*)encoding);
-        xmlFree( realstring ); 
-        xmlFree( tstr );
+            realstring = Sv2C(string,"UTF8" );
+            tstr =  domDecodeString( encoding, realstring );
+            RETVAL = C2Sv(tstr,(xmlChar*)encoding);
+            xmlFree( realstring ); 
+            xmlFree( tstr );
 #ifdef HAVE_UTF8
         }
 #endif
 {
     ProxyObject * dfProxy= NULL;
     SV * retval = &PL_sv_undef;
-    char * CLASS = "XML::LibXML::Node";
+    const char * CLASS = "XML::LibXML::Node";
     
     if ( node != NULL ) {
         /* find out about the class */

t/02parsestring.t

 use Test;
 use Devel::Peek;
 
-BEGIN { plan tests => 10 };
+BEGIN { plan tests => 13 };
 use XML::LibXML;
 ok(1);
 
 
 # warn "doc is: ", $doc2->toString, "\n";
 
+eval { my $fail = $parser->parse_string(""); };
+# warn "# $@\n";
+ok($@);
+
 ## 
 # phish: parse_xml_chunk tests
 
 $badchunk = "foo</bar>foobar";
 $fragment = $parser->parse_xml_chunk( $badchunk );
 ok( !$fragment );
+
+$badchunk = "";
+eval {
+    $fragment = $parser->parse_xml_chunk( $badchunk );
+};
+ok( !$fragment );
+
+$badchunk = undef;
+eval {
+    $fragment = $parser->parse_xml_chunk( $badchunk );
+};
+ok( !$fragment );