File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -498,6 +498,17 @@ sub _parse_version_expression {
498
498
sub _handle_bom {
499
499
my ($self , $fh , $filename ) = @_ ;
500
500
501
+ my $UTF8_BOM ;
502
+ if ( " $] " >= 5.008 ) {
503
+
504
+ # Works on EBCDIC too
505
+ $UTF8_BOM = " \x{FEFF} " ;
506
+ utf8::encode($UTF8_BOM );
507
+ }
508
+ else {
509
+ $UTF8_BOM = " \x{EF}\x{BB}\x{BF} " ;
510
+ }
511
+
501
512
my $pos = tell $fh ;
502
513
return unless defined $pos ;
503
514
@@ -512,10 +523,10 @@ sub _handle_bom {
512
523
elsif ( $buf eq " \x{FF}\x{FE} " ) {
513
524
$encoding = ' UTF-16LE' ;
514
525
}
515
- elsif ( $buf eq " \x{EF}\x{BB} " ) {
516
- $buf = ' ' ;
526
+ elsif ( $buf eq substr ( $UTF8_BOM , 0, 2) ) {
527
+ $buf = ' ' x ( length ( $UTF8_BOM ) - 2) ;
517
528
$count = read $fh , $buf , length $buf ;
518
- if ( defined $count and $count >= 1 and $buf eq " \x{BF} " ) {
529
+ if ( defined $count and $count >= 1 and $buf eq substr ( $UTF8_BOM , 2) ) {
519
530
$encoding = ' UTF-8' ;
520
531
}
521
532
}
You can’t perform that action at this time.
0 commit comments