]> git.donarmstrong.com Git - perltidy.git/commitdiff
fix an issue with line-ending blanks (c258)
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 21 Aug 2023 00:10:07 +0000 (17:10 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 21 Aug 2023 00:10:07 +0000 (17:10 -0700)
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

index bb6d961b944ffff2e5184aa434690fd8fe8a432e..00c7e07b1881696ce493d001979b2ff0f1c0a599 100644 (file)
@@ -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);