Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse errors via xpcroak do not count as errors. [rt.cpan.org #54225] #50

Open
toddr opened this issue Sep 24, 2019 · 0 comments
Open
Labels

Comments

@toddr
Copy link
Member

toddr commented Sep 24, 2019

Migrated from rt.cpan.org#54225 (status was 'new')

Requestors:

From kevin_frost@symantec.com on 2010-02-02 17:45:55
:

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;



@toddr toddr added the Has Test label Sep 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant