]> git.donarmstrong.com Git - perltidy.git/commitdiff
Fix some problems involving tabs characters, issue c062
authorSteve Hancock <perltidy@users.sourceforge.net>
Thu, 19 Aug 2021 14:17:49 +0000 (07:17 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Thu, 19 Aug 2021 14:17:49 +0000 (07:17 -0700)
lib/Perl/Tidy/Formatter.pm
lib/Perl/Tidy/Tokenizer.pm
local-docs/BugLog.pod

index 27591e13be320028f1bcff2ee0546cb66b6200f5..68b779746c0c6f6b70072126e6454f072349963b 100644 (file)
@@ -9614,7 +9614,8 @@ EOM
             my $token_beg = $rLL->[$Kbeg]->[_TOKEN_];
 
             # allow space(s) after the qw
-            if ( length($token_beg) > 3 && substr( $token_beg, 2, 1 ) eq ' ' ) {
+            if ( length($token_beg) > 3 && substr( $token_beg, 2, 1 ) =~ m/\s/ )
+            {
                 $token_beg =~ s/\s+//;
             }
 
index c5f955ee97863f4fa9c1e614d21bd7a3a295f97f..354c8154358771ed5e0e050a341134e7088c62e3 100644 (file)
@@ -6150,7 +6150,7 @@ sub guess_if_pattern_or_division {
         # usually indicates a pattern.  We can use this to break ties.
 
         my $is_pattern_by_spacing =
-          ( $i > 1 && $next_token ne ' ' && $rtokens->[ $i - 2 ] eq ' ' );
+          ( $i > 1 && $next_token !~ m/^\s/ && $rtokens->[ $i - 2 ] =~ m/^\s/ );
 
         # look for a possible ending / on this line..
         my $in_quote        = 1;
@@ -7620,15 +7620,16 @@ sub scan_identifier_do {
                     $max_token_index );
                 if ($error) { warning("Possibly invalid sub\n") }
 
-            # Patch part #2 to fixes cases b994 and b1053:
-            # Do not let spaces be part of the token of an anonymous sub keyword
-            # which we marked as type 'k' above...i.e. for something like:
-            #    'sub : lvalue { ...'
-            # Back up and let it be parsed as a blank
+                # Patch part #2 to fixes cases b994 and b1053:
+                # Do not let spaces be part of the token of an anonymous sub
+                # keyword which we marked as type 'k' above...i.e. for
+                # something like:
+                #    'sub : lvalue { ...'
+                # Back up and let it be parsed as a blank
                 if (   $type eq 'k'
                     && $attrs
                     && $i > $i_entry
-                    && substr( $rtokens->[$i], 0, 1 ) eq ' ' )
+                    && substr( $rtokens->[$i], 0, 1 ) =~ m/\s/ )
                 {
                     $i--;
                 }
index e8a517ca9091d4c88e34c2af132372dcbc96c9a6..470f64b0c65fae5da27db186a8e7c9a0d1571e96 100644 (file)
@@ -2,6 +2,43 @@
 
 =over 4
 
+=item B<Fix some problems involving tabs characters, case c062>
+
+This update fixes some problems found in random testing with tab characters.
+For example, In the following snippet there is a tab character after 'sub'
+
+    do sub     : lvalue {
+        return;
+      }
+
+Running perltidy on this repeatedly keep increasing the space between
+'sub' and ':'
+
+    # OLD: perltidy
+    do sub      : lvalue {
+        return;
+      }
+
+    # OLD: perltidy
+    do sub       : lvalue {
+        return;
+      }
+
+etc.
+
+    # NEW: perltidy
+    do sub : lvalue {
+        return;
+      }
+
+Problems like this can occur if string comparisons use ' ' instead of
+the regex \s when working on spaces. Several instances of this were located
+and corrected.
+
+This fixes issue c062.
+
+18 Aug 2021.
+
 =item B<Correct parsing error, case c061>
 
 Testing with random input produced an error condition involving a