263dded818
use encoding(UTF-8) rather than utf-8 for stricter encoding Marking output as ':utf8' only flags the data as utf8 using :encoding(UTF-8) also checks it as valid utf-8 see binmode in perlfunc for more details In accordance with the robustness principle input filehandles have not been changed as code may make the undocumented assumption that invalid utf-8 is present in the imput Fixes errors reported by t/00-testcritic.t Where feasable some filehandles have been made lexical rather than reusing global filehandle vars Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com> Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
28 lines
546 B
Perl
Executable file
28 lines
546 B
Perl
Executable file
#!/usr/bin/perl
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use XML::SAX;
|
|
use Encode;
|
|
|
|
my $parser = XML::SAX::ParserFactory->parser(
|
|
Handler => MySAXHandler->new
|
|
);
|
|
binmode STDOUT, ':encoding(UTF-8)';
|
|
print "\x{65}\x{301}\n";
|
|
$parser->parse_string(encode_utf8("<xml>\x{65}\x{301}</xml>"));
|
|
$parser->parse_string("<xml>\xEF\xBB\xBF\x{65}\x{301}</xml>");
|
|
|
|
package MySAXHandler;
|
|
|
|
use base qw(XML::SAX::Base);
|
|
sub start_document {
|
|
my ($self, $doc) = @_;
|
|
# process document start event
|
|
}
|
|
|
|
sub start_element {
|
|
my ($self, $el) = @_;
|
|
# process element start event
|
|
}
|