From 5c74780779ad5ec9e6ba0f3e1a629539d902931b Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Fri, 8 Mar 2019 23:31:26 -0600 Subject: [PATCH] fix Windows EOL translation error with UTF-8 .# Discussion When using `binmode ... ":encoding(UTF8)"`, the CRLF translation layer is left in-place. As used prior to this commit, on Windows machines, this `binmode` setting causes the output file to be converted to "DOS" CRLF line endings regardless of other settings. `binmode ... ":raw:encoding(UTF8)"` will enable UTF-8 without the CRLF translation layer. --- lib/Perl/Tidy.pm | 2 +- lib/Perl/Tidy/LineSink.pm | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index 543754eb..cfcbdc4c 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -1297,7 +1297,7 @@ EOM if ( $rOpts->{'character-encoding'} && $rOpts->{'character-encoding'} eq 'utf8' ) { - binmode $fout, ":encoding(UTF-8)"; + binmode $fout, ":raw:encoding(UTF-8)"; } else { binmode $fout } } diff --git a/lib/Perl/Tidy/LineSink.pm b/lib/Perl/Tidy/LineSink.pm index 8e3a7c38..7d9f4a14 100644 --- a/lib/Perl/Tidy/LineSink.pm +++ b/lib/Perl/Tidy/LineSink.pm @@ -29,10 +29,10 @@ sub new { && $rOpts->{'character-encoding'} eq 'utf8' ) { if ( ref($fh) eq 'IO::File' ) { - $fh->binmode(":encoding(UTF-8)"); + $fh->binmode(":raw:encoding(UTF-8)"); } elsif ( $output_file eq '-' ) { - binmode STDOUT, ":encoding(UTF-8)"; + binmode STDOUT, ":raw:encoding(UTF-8)"; } } -- 2.39.5