Skip to content

Commit

Permalink
Better workaround for Windows encoding issue.
Browse files Browse the repository at this point in the history
Aaron Crane did some testing, and found that the error can be suppressed by
any of:

- removing the :crlf layer
- using the :utf8 layer instead of :encoding(UTF-8)
- using a file that ends in \r\n rather than \n
- removing the C<< eof $fh >> test
- leaving $/ unmodified, rather than setting it to undef

So I decided to remove the $/. Removes a line of code, too.
  • Loading branch information
theory committed Mar 7, 2016
1 parent 7443b48 commit 9839d40
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Revision history for Test-File-Contents

0.23
- Fix Windows encoding conversion by reading files in raw bytes before
converting to the encoding.
- Fix encoding errors when reading in a file on Windows with `utf8`
enabled. See https://rt.perl.org/Ticket/Display.html?id=127668 for the
bug we've worked around.

0.22 2016-03-02T23:54:26Z
- Adjusted tests to account for change in output of Text::Diff 1.44.
Expand Down
7 changes: 4 additions & 3 deletions lib/Test/File/Contents.pm
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,12 @@ sub _slurp {
my ($file, $encoding) = @_;
my $layer = !$encoding ? ''
: $encoding =~ '^:' ? $encoding
: ":raw:encoding($encoding)";
: ":encoding($encoding)";
open my $fh, "<$layer", $file or return;
return '' if eof $fh;
local $/;
return <$fh>;
# Don't use `local $/; return <$fh>;`, it does not work on Windows.
# See https://rt.perl.org/Ticket/Display.html?id=127668 for details.
return join '', <$fh>;
}

sub _resolve {
Expand Down

0 comments on commit 9839d40

Please sign in to comment.