From: Steve Hancock Date: Thu, 19 Aug 2021 14:17:49 +0000 (-0700) Subject: Fix some problems involving tabs characters, issue c062 X-Git-Tag: 20210717.02~37 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=d86787f0d840291cde69a524efecd058f60c6391;p=perltidy.git Fix some problems involving tabs characters, issue c062 --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 27591e13..68b77974 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -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+//; } diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index c5f955ee..354c8154 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -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--; } diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index e8a517ca..470f64b0 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,43 @@ =over 4 +=item B + +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 Testing with random input produced an error condition involving a