1# tell parser the source POD has already been decoded from bytes to chars 2# =encoding line should be ignored 3# utf8 characters should come through unscathed 4 5BEGIN { 6 if($ENV{PERL_CORE}) { 7 chdir 't'; 8 @INC = '../lib'; 9 } 10 11 use Config; 12 if ($Config::Config{'extensions'} !~ /\bEncode\b/) { 13 print "1..0 # Skip: Encode was not built\n"; 14 exit 0; 15 } 16} 17 18use strict; 19use Test; 20BEGIN { plan tests => 5 }; 21 22use Pod::Simple::DumpAsXML; 23use Pod::Simple::XMLOutStream; 24 25my $parser = Pod::Simple::XMLOutStream->new; 26$parser->parse_characters(1); 27my $output = ''; 28$parser->output_string( \$output ); 29$parser->parse_string_document(qq{ 30 31=encoding bogocode 32 33=head1 DESCRIPTION 34 35Confirm that if we tell the parser to expect character data, it avoids all 36the code paths that might attempt to decode the source from bytes to chars. 37 38The r\x{101}in in \x{15E}pain \x{FB02}oods the plain 39 40}); 41 42ok(1); # parsed without exception 43 44if($output =~ /POD ERRORS/) { 45 ok(0); 46} 47else { 48 ok(1); # no errors 49} 50 51$output =~ s{&#(\d+);}{chr($1)}eg; 52 53if($output =~ /The r\x{101}in in \x{15E}pain \x{FB02}oods the plain/) { 54 ok(1); # data was not messed up 55} 56else { 57 ok(0); 58} 59 60############################################################################## 61# Test multiple =encoding declarations. 62$parser = Pod::Simple::XMLOutStream->new; 63$output = ''; 64$parser->output_string( \$output ); 65$parser->parse_string_document(qq{ 66 67=pod 68 69=encoding UTF-8 70 71=encoding UTF-8 72 73=head1 DESCRIPTION 74 75Confirm that the parser detects multiple encodings and complains. 76}); 77 78# Should have an error. 79ok($output =~ /POD ERRORS/); 80ok($output =~ /Cannot have multiple =encoding directives/); 81 82exit; 83