]> git.donarmstrong.com Git - perltidy.git/commitdiff
fix Windows EOL translation error with UTF-8
authorRoy Ivy III <rivy.dev@gmail.com>
Sat, 9 Mar 2019 05:31:26 +0000 (23:31 -0600)
committerRoy Ivy III <rivy.dev@gmail.com>
Sat, 9 Mar 2019 08:23:29 +0000 (02:23 -0600)
.# 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
lib/Perl/Tidy/LineSink.pm

index 543754ebf014a413487802d2afaf6d5229f93c48..cfcbdc4cf696d9aa1b623664722d0905b0a169c7 100644 (file)
@@ -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 }
             }
index 8e3a7c38fb407311c995ef681993fa8de0c748d4..7d9f4a14b5f16bf82ce2b1d0906de8f0028fd23c 100644 (file)
@@ -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)";
                 }
             }