From c5fa232bf7bff59f9a58e600928fe92f6404098b Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Fri, 20 Mar 2020 19:46:26 -0700 Subject: [PATCH] added check for strings already encoded utf8 --- lib/Perl/Tidy.pm | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index 12e4a2b9..bc2dc9d7 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -959,18 +959,20 @@ EOM # Case 3. Decode with a specific encoding else { $encoding_in = $rOpts->{'character-encoding'}; - eval { - $buf = Encode::decode( $encoding_in, $buf, - Encode::FB_CROAK | Encode::LEAVE_SRC ); - }; - if ($@) { - - # Quit if we cannot decode by the requested encoding; - # Something is not right. - Warn( + if ( !utf8::is_utf8($buf) ) { + eval { + $buf = Encode::decode( $encoding_in, $buf, + Encode::FB_CROAK | Encode::LEAVE_SRC ); + }; + if ($@) { + + # Quit if we cannot decode by the requested encoding; + # Something is not right. + Warn( "skipping file: $input_file: Unable to decode source as $encoding_in\n" - ); - next; + ); + next; + } } } -- 2.39.5