From 7d3af9d23e8eb9d12864af045f86d6ae0e531532 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sat, 7 Oct 2023 08:02:48 -0700 Subject: [PATCH] fix --presereve-line-endings + --noadd-terminal-newline issue; c283 --- lib/Perl/Tidy.pm | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index 0429f297..821d56ff 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -2391,7 +2391,7 @@ sub write_tidy_output { return; -} ## end sub write_tidied_output +} ## end sub write_tidy_output sub process_filter_layer { @@ -2572,6 +2572,13 @@ EOM $routput_string = \$output_string; } + #----------------------------------------- + # handle a '--noadd-terminal-newline' flag + #----------------------------------------- + if ($chomp_terminal_newline) { + chomp ${$routput_string}; + } + #------------------------------------------------------------- # handle --preserve-line-endings or -output-line-endings flags #------------------------------------------------------------- @@ -2582,22 +2589,19 @@ EOM my $line_separator = $self->[_line_separator_]; my @output_lines = split /^/, ${$routput_string}; foreach my $line (@output_lines) { - chomp $line; - $line .= $line_separator; + + # must check chomp because last line might not have a newline + # if --noadd-terminal-newline is also set (c283) + if ( chomp $line ) { + $line .= $line_separator; + } } my $output_string = join EMPTY_STRING, @output_lines; $routput_string = \$output_string; } - #----------------------------------------- - # handle a '--noadd-terminal-newline' flag - #----------------------------------------- - if ($chomp_terminal_newline) { - chomp ${$routput_string}; - } - return $routput_string; -} +} ## end sub process_filter_layer # For safety, set an upper bound on number of iterations before stopping. # The average number of iterations is 2. No known cases exceed 5. -- 2.39.5