Package: libxml-libxml-perl Version: 1.58-0.3 Severity: normal Hi,
the XML::LibXML::SAX parser does not raise an exception by default when parsing invalid XML syntax. The other available SAX parsers on my system, XML::LibXML::SAX::Parser (from the same libxml-libxml-perl package) and XML::SAX::PurePerl (from libxml-sax-perl) do raise exceptions by default, so this is inconsistent behaviour. I'm attaching a test script that shows the problem. It defines a simple XML handling class, MyHandler, which is derived from XML::SAX::Base, and uses it to parse an invalid XML document with different SAX parsers. The result output is: %./saxtest.pl Trying parser XML::LibXML::SAX::Parser...OK: got exception Trying parser XML::SAX::PurePerl...OK: got exception Trying parser XML::LibXML::SAX...ERROR: no exception When called with the '-2' parameter, it uses another handling class, MyHandler2, that differs from MyHandler only in that it has an explicit 'error' method. The resulting output is now; % ./saxtest.pl -2 Trying parser XML::LibXML::SAX::Parser...OK: got exception Trying parser XML::SAX::PurePerl...OK: got exception Trying parser XML::LibXML::SAX...OK: got exception (There's also a "-v" parameter that shows the error string, in case you want to verify the cause of the exception.) Note that XML::LibXML::SAX is the default SAX parser when libxml-libxml-perl is installed, so it would seem even more important for it to do the Right Thing. I ran into the problem while inspecting test failures in libxtm-perl, bug #249234. I'll send details there shortly. Cheers, -- Niko Tyni [EMAIL PROTECTED]
#!/usr/bin/perl -w use strict; use XML::SAX; use XML::SAX::ParserFactory; use XML::LibXML::SAX; use Getopt::Std; my %opts; getopts('2v', \%opts); my @parsers = map { $_->{Name} } @{XML::SAX->parsers()}; my $h; if ($opts{2}) { $h = new MyHandler2; } else { $h = new MyHandler; } for (@parsers) { print "Trying parser $_..."; local $XML::SAX::ParserPackage = $_; my $p = XML::SAX::ParserFactory->parser(Handler => $h); eval { $p->parse_string(q|<?xml version="1.0"?><a/><a/>|) }; if ($@) { print "OK: got exception\n"; print $@ if $opts{v}; } else { print "ERROR: no exception\n"; } print "\n"; } package MyHandler; use base qw(XML::SAX::Base); 1; package MyHandler2; use base qw(XML::SAX::Base); sub error { my $self = shift; die(shift); } 1;