From 84aac28f7709aefee8c4240a964d27f94d834dd3 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Wed, 4 Oct 2023 21:07:03 -0700 Subject: [PATCH] update fault check to handle zero length file (c286) --- lib/Perl/Tidy/Tokenizer.pm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index 94b0a97c..6b0ae8cb 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -657,7 +657,7 @@ EOM # the whole input file at once than line-by-line. # Add a terminal newline if needed to keep line count unchanged (c283) - if ( $source_string !~ /\n$/ ) { $source_string .= "\n" } + if ( $source_string && $source_string !~ /\n$/ ) { $source_string .= "\n" } # Remove leading whitespace except newlines $source_string =~ s/^ [^\S\n]+ //gxm; @@ -669,8 +669,11 @@ EOM if ( @trimmed_lines != @{$rinput_lines} ) { # Shouldn't happen - die in DEVEL_MODE and fix + my $ntr = @trimmed_lines; + my $utr = @{$rinput_lines}; DEVEL_MODE - && $self->Fault("trimmed/untrimmed line counts differ\n"); + && $self->Fault( + "trimmed / untrimmed line counts differ: $ntr / $utr\n"); # Otherwise we can safely continue with undefined trimmed lines. They # will be detected and fixed later. -- 2.39.5