]> git.donarmstrong.com Git - perltidy.git/commitdiff
add extra safety check for the -scbb -csc problem
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 5 Sep 2020 03:59:23 +0000 (20:59 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 5 Sep 2020 03:59:23 +0000 (20:59 -0700)
lib/Perl/Tidy/VerticalAligner.pm

index 7a87109f89062c2bf9d8f7c3fdfbda3be929fabe..7c799d9e6f47b41113015aeb8eb3c8ef965d723a 100644 (file)
@@ -4137,6 +4137,18 @@ sub get_output_line_number {
         my $line        = $leading_string . $str;
         my $line_length = $leading_string_length + $str_length;
 
+       # Safety check: be sure that a line to be cached as a stacked block
+       # brace line ends in the appropriate opening or closing block brace.
+       # This should always be the case if the caller set flags correctly.
+       # Code '3' is for -sobb, code '4' is for -scbb.
+        if ($open_or_close) {
+            if (   $open_or_close == 3 && $line !~ /\{\s*$/
+                || $open_or_close == 4 && $line !~ /\}\s*$/ )
+            {
+                $open_or_close = 0;
+            }
+        } 
+
         # write or cache this line
         if ( !$open_or_close || $side_comment_length > 0 ) {
             $self->valign_output_step_C( $line, $leading_space_count, $level );