From: Steve Hancock Date: Mon, 21 Aug 2023 00:10:07 +0000 (-0700) Subject: fix an issue with line-ending blanks (c258) X-Git-Tag: 20230701.03~8 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=8a2dff2749dc8e125efb3f70b8c695843ab6f979;p=perltidy.git 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. --- 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);