Subject: | Parse errors via xpcroak do not count as errors. |
Date: | Tue, 2 Feb 2010 18:45:07 +0100 |
To: | bug-XML-Parser [...] rt.cpan.org |
From: | Kevin Frost <kevin_frost [...] symantec.com> |
Hello.
I believe I've found a bug in XML::Parser. A test is included below.
The problem is that XML::Parser is over-aggressve in trapping parse errors, and as a result the xpcroak() method in XML::Parser::Expat can not be used to raise a parse error.
This is frustrating since I would like to abort processing in large documents when certain conditions occur, and I would also like to know what happened. According to the documentation, xpcroak() should be the proper way to do that.
Versions in use:
XML::Parser: 2.36
XML::Parser::Expat: 2.36
Perl: v5.10.0
OS: OS X 10.6.2 (Mac Snow Leopard)
cheers
-- Kevin Frost
# It appears that XML::Parser 2.36 is not correctly handling
# XML::Parser::expat's xpcroak() method.
#
# The POD says, under parse: "A die call is thrown if a parse error occurs."
use strict;
use warnings;
use Test::More tests => 5;
BEGIN {
use_ok('XML::Parser');
cmp_ok( $XML::Parser::VERSION, '>=', 2.36, "version at least 2.36" );
}
test_bug();
sub test_bug {
# We do a simple parse:
my $xml = '<foo id="me">Hello World</foo>';
my $parser = XML::Parser->new( Style => 'Subs', Pkg => 'ParseBugDemo' );
my $res = $parser->parse($xml);
# We make sure our parse class behaved constently:
ok( $ParseBugDemo::I_DONE_CROAKED, "parsing should have croaked" );
ok( !$ParseBugDemo::CROAK_NOT_DEADLY, "croak aborted subroutine" );
# And here we see the bug, in that the following fails:
ok( !$res, "result of an xpcroaked parse is NOT true" );
}
# Here is our parser class for the "Subs" parsing style.
package ParseBugDemo;
our $I_DONE_CROAKED = 0;
our $CROAK_NOT_DEADLY = 0;
sub foo {
my $expat = shift;
$I_DONE_CROAKED = 1;
$expat->xpcroak("I croaketh.");
$CROAK_NOT_DEADLY = 1;
}
1;