From 8a2dff2749dc8e125efb3f70b8c695843ab6f979 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sun, 20 Aug 2023 17:10:07 -0700 Subject: [PATCH] fix an issue with line-ending blanks (c258) No real cases have been found where this changes formatting, but it is possible to construct a case where it could produce unwanted spacing just on the first time perltidy is run. It would be corrected on the next run because perltidy trims trailing blanks from code lines. --- lib/Perl/Tidy/Tokenizer.pm | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index bb6d961b..00c7e07b 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -8888,6 +8888,17 @@ sub find_next_nonblank_token { # To skip past a side comment, and any subsequent block comments # and blank lines, call with i=$max_token_index + # Skip any ending blank (fix c258). It would be cleaner if caller passed + # $rtoken_map, so we could check for type 'b', and avoid a regex test, but + # benchmarking shows that this test does not take significant time. So + # that would be a nice update but not essential. Also note that ending + # blanks will not occur for text previously processed by perltidy. + if ( $i == $max_token_index - 1 + && $rtokens->[$max_token_index] =~ /^\s+$/ ) + { + $i++; + } + if ( $i >= $max_token_index ) { if ( !peeked_ahead() ) { peeked_ahead(1); -- 2.39.5