From: Steve Hancock Date: Mon, 8 Nov 2021 23:52:39 +0000 (-0800) Subject: fix c104, error reformatting '$ 0' X-Git-Tag: 20211029.01~22 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=4442ba50ab98afc7c835af7ce61bb6b7c22275d9;p=perltidy.git fix c104, error reformatting '$ 0' --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index f38cba87..08379196 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -6508,7 +6508,7 @@ sub respace_tokens { # $sigil =~ /^[\$\&\%\*\@]$/ ) if ( $is_sigil{$sigil} ) { $token = $sigil; - $token .= $word if ($word); + $token .= $word if ( defined($word) ); # fix c104 $rtoken_vars->[_TOKEN_] = $token; } } diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index d3bd2fd6..8f29937b 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,33 @@ =over 4 +=item B + +Automated random testing produced an error with something like the following +input line taken from an obfuscated perl script: + + open(IN, $ 0); + +The '0' was missing in the output: + + open( IN, $ ); + +The tokenization was correct, but a line of code in the formatter which +removes the space between the '$' and the '0' should have used a 'defined' +when doing a check: + + $token .= $word if ($word); # OLD: error + +This if test fails on '0'. The corrected line is + + $token .= $word if ( defined($word) ); # NEW: fixes c104 + +This fixes the problem and gives the correct formatted result + + open( IN, $0 ); + +8 Nov 2021. + =item B Random testing produced an undefined variable reference for the following input