~ubuntu-branches/ubuntu/trusty/libxml-libxml-perl/trusty-security

« back to all changes in this revision

Viewing changes to t/02parse.t

  • Committer: Package Import Robot
  • Author(s): Alessandro Ghedini
  • Date: 2012-10-16 14:10:26 UTC
  • mfrom: (1.2.26)
  • Revision ID: package-import@ubuntu.com-20121016141026-3x0th9su7cue9hl0
Tags: 2.0006+dfsg-1
* New upstream release
* Refresh patches
* Bump Standards-Version to 3.9.4 (no changes needed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
my @badWFStrings = (
63
63
"",                                        # totally empty document
64
64
XML_DECL,                                  # only XML Declaration
65
 
"<!--ouch-->",                             # comment only is like an empty document 
 
65
"<!--ouch-->",                             # comment only is like an empty document
66
66
'<!DOCTYPE ouch [<!ENTITY foo "bar">]>',   # no good either ...
67
67
"<ouch>",                                  # single tag (tag mismatch)
68
68
"<ouch/>foo",                              # trailing junk
75
75
"<ouch>&foo;</ouch>",                      # undefind entity
76
76
"<ouch>&gt</ouch>",                        # unterminated entity
77
77
XML_DECL. '<!DOCTYPE foobar [<!ENTITY foo "bar">]><foobar &foo;="ouch"/>',          # bad placed entity
78
 
XML_DECL. '<!DOCTYPE foobar [<!ENTITY foo "bar=&quot;foo&quot;">]><foobar &foo;/>', # even worse 
 
78
XML_DECL. '<!DOCTYPE foobar [<!ENTITY foo "bar=&quot;foo&quot;">]><foobar &foo;/>', # even worse
79
79
"<ouch><!---></ouch>",                     # bad comment
80
80
'<ouch><!-----></ouch>',                   # bad either... (is this conform with the spec????)
81
81
                    );
221
221
    my $doc = $parser->parse_file($goodfile);
222
222
    isa_ok($doc, 'XML::LibXML::Document');
223
223
}
224
 
 
 
224
 
225
225
eval {my $fail = $parser->parse_file($badfile1);};
226
226
like($@, qr/^$badfile1:3: parser error : Extra content at the end of the document/, "error parsing $badfile1");
227
227
 
289
289
 
290
290
my $goodXInclude = q{
291
291
<x>
292
 
<xinclude:include 
 
292
<xinclude:include
293
293
 xmlns:xinclude="http://www.w3.org/2001/XInclude"
294
294
 href="test2.xml"/>
295
295
</x>
327
327
    like($@, qr/$badfile1:3: parser error : Extra content at the end of the document/, "error parsing $badfile1 in include");
328
328
    is($doc, undef, "no doc returned");
329
329
 
330
 
    # some bad stuff 
 
330
    # some bad stuff
331
331
    eval{ $parser->processXIncludes(undef); };
332
332
    like($@, qr/^No document to process! at/, "Error parsing undef include");
333
333
 
340
340
{
341
341
    my $pparser = XML::LibXML->new();
342
342
    # 2.1 PARSING WELLFORMED DOCUMENTS
343
 
    foreach my $key ( qw(single1 single2 single3 single4 single5 single6 
 
343
    foreach my $key ( qw(single1 single2 single3 single4 single5 single6
344
344
                         single7 single8 single9 multiple1 multiple2 multiple3
345
 
                         multiple4 multiple5 multiple6 multiple7 multiple8 
 
345
                         multiple4 multiple5 multiple6 multiple7 multiple8
346
346
                         multiple9 multiple10 comment1 comment2 comment3
347
347
                         comment4 comment5 attr1 attr2 attr3
348
348
                         ns1 ns2 ns3 ns4 ns5 ns6 dtd1 dtd2) ) {
357
357
    }
358
358
 
359
359
    my @good_strings = ("<foo>", "bar", "</foo>" );
360
 
    my %bad_strings  = ( 
 
360
    my %bad_strings  = (
361
361
                            predocend1   => ["<A>" ],
362
362
                            predocend2   => ["<A>", "B"],
363
363
                            predocend3   => ["<A>", "<C>"],
372
372
 
373
373
    my $parser = XML::LibXML->new;
374
374
    {
375
 
        for ( @good_strings ) {        
 
375
        for ( @good_strings ) {
376
376
            $parser->parse_chunk( $_ );
377
377
        }
378
378
        my $doc = $parser->parse_chunk("",1);
399
399
                next;
400
400
            }
401
401
 
402
 
            eval {    
 
402
            eval {
403
403
                $doc = $parser->parse_chunk("",1);
404
404
            };
405
405
            isnt($@, '', "Got an error parsing empty chunk after chunks for $key");
479
479
    my $root = $doc->documentElement;
480
480
 
481
481
    # bad thing: i have to do some NS normalizing.
482
 
    # libxml2 will only do some fixing. this will lead to multiple 
 
482
    # libxml2 will only do some fixing. this will lead to multiple
483
483
    # declarations, if a node with a new namespace is added.
484
484
 
485
485
    my $vstring = q{<foo xmlns:bar="http://foo.bar">bar<bar:bi/></foo>};
499
499
 
500
500
    # 3.6 PARSE CHUNK
501
501
 
502
 
        
 
502
 
503
503
}
504
504
 
505
505
# 4 SAXY PUSHER
529
529
    my $MAX_WF_C = 11;
530
530
    my $MAX_WB_C = 16;
531
531
 
532
 
    my %chunks = ( 
 
532
    my %chunks = (
533
533
                    wellformed1  => '<A/>',
534
534
                    wellformed2  => '<A></A>',
535
535
                    wellformed3  => '<A B="C"/>',
539
539
                    wellformed7  => '<A><K/></A>',
540
540
                    wellformed8  => '<A xmlns="xml://E"/>',
541
541
                    wellformed9  => '<F:A xmlns:F="xml://G" F:A="B">D</F:A>',
542
 
                    wellformed10 => '<!--D-->',      
543
 
                    wellformed11  => '<A xmlns:F="xml://E"/>',              
 
542
                    wellformed10 => '<!--D-->',
 
543
                    wellformed11  => '<A xmlns:F="xml://E"/>',
544
544
                    wellbalance1 => '<A/><A/>',
545
545
                    wellbalance2 => '<A></A><A></A>',
546
546
                    wellbalance3 => '<A B="C"/><A B="H"/>',
549
549
                    wellbalance6 => '<A><![CDATA[D]]></A><A><![CDATA[I]]></A>',
550
550
                    wellbalance7 => '<A><!--D--></A><A><!--I--></A>',
551
551
                    wellbalance8 => '<F:A xmlns:F="xml://G" F:A="B">D</F:A><J:A xmlns:J="xml://G" J:A="M">D</J:A>',
552
 
                    wellbalance9 => 'D<A/>',                    
 
552
                    wellbalance9 => 'D<A/>',
553
553
                    wellbalance10=> 'D<A/>D',
554
554
                    wellbalance11=> 'D<A/><!--D-->',
555
555
                    wellbalance12=> 'D<A/><![CDATA[D]]>',
573
573
 
574
574
 
575
575
    my $pparser = XML::LibXML->new;
576
 
    
 
576
 
577
577
    # 5.1 DOM CHUNK PARSER
578
578
 
579
579
    for ( 1..$MAX_WF_C ) {
791
791
 
792
792
    is( $parser->parse_string( $xsDoc1 )->documentElement->toString(),
793
793
        q{<A:B xmlns:A="http://D"><A:C/></A:B>} );
794
 
    is( $parser->parse_string( $xsDoc2 )->documentElement->toString(), 
795
 
        $xsDoc2 );
796
 
 
797
 
    is( $parser->parse_file( $fn1  )->documentElement->toString(), 
798
 
        q{<A:B xmlns:A="http://D"><A:C/></A:B>} );
799
 
    is( $parser->parse_file( $fn2 )->documentElement->toString() , 
800
 
        $xsDoc2 );
801
 
    
802
 
    my $fh1 = IO::File->new($fn1);  
803
 
    my $fh2 = IO::File->new($fn2);  
804
 
 
805
 
    is( $parser->parse_fh( $fh1  )->documentElement->toString(), 
806
 
        q{<A:B xmlns:A="http://D"><A:C/></A:B>} );
807
 
    is( $parser->parse_fh( $fh2 )->documentElement->toString() , 
 
794
    is( $parser->parse_string( $xsDoc2 )->documentElement->toString(),
 
795
        $xsDoc2 );
 
796
 
 
797
    is( $parser->parse_file( $fn1  )->documentElement->toString(),
 
798
        q{<A:B xmlns:A="http://D"><A:C/></A:B>} );
 
799
    is( $parser->parse_file( $fn2 )->documentElement->toString() ,
 
800
        $xsDoc2 );
 
801
 
 
802
    my $fh1 = IO::File->new($fn1);
 
803
    my $fh2 = IO::File->new($fn2);
 
804
 
 
805
    is( $parser->parse_fh( $fh1  )->documentElement->toString(),
 
806
        q{<A:B xmlns:A="http://D"><A:C/></A:B>} );
 
807
    is( $parser->parse_fh( $fh2 )->documentElement->toString() ,
808
808
        $xsDoc2 );
809
809
 
810
810
    my @xaDoc1 = ('<A:B xmlns:A="http://D">','<A:C xmlns:A="h','ttp://D"/>' ,'</A:B>');
816
816
        $parser->parse_chunk( $_ );
817
817
    }
818
818
    $doc = $parser->parse_chunk( "", 1 );
819
 
    is( $doc->documentElement->toString(), 
 
819
    is( $doc->documentElement->toString(),
820
820
        q{<A:B xmlns:A="http://D"><A:C/></A:B>} );
821
821
 
822
822
 
824
824
        $parser->parse_chunk( $_ );
825
825
    }
826
826
    $doc = $parser->parse_chunk( "", 1 );
827
 
    is( $doc->documentElement->toString() , 
 
827
    is( $doc->documentElement->toString() ,
828
828
        $xsDoc2 );
829
829
};
830
830
 
838
838
<X>&foo;</X>
839
839
EOXML
840
840
        my $parser = XML::LibXML->new();
841
 
        
 
841
 
842
842
        $parser->load_ext_dtd(1);
843
843
 
844
844
        # first time it should work
845
845
        my $doc    = $parser->parse_string( $xmldoc );
846
846
        is( $doc->documentElement()->string_value(), " test " );
847
847
 
848
 
        # second time it must not fail.        
 
848
        # second time it must not fail.
849
849
        my $doc2   = $parser->parse_string( $xmldoc );
850
850
        is( $doc2->documentElement()->string_value(), " test " );
851
851
}
852
852
 
853
853
##
854
 
# Test ticket #7668 xinclude breaks entity expansion 
 
854
# Test ticket #7668 xinclude breaks entity expansion
855
855
# [CG] removed again, since #7668 claims the spec is incorrect
856
856
 
857
857
##
862
862
<X>&foo;</X>
863
863
EOXML
864
864
        my $parser = XML::LibXML->new();
865
 
        
 
865
 
866
866
        $parser->load_ext_dtd(1);
867
867
 
868
868
        # first time it should work