]> git.donarmstrong.com Git - perltidy.git/commitdiff
fix c104, error reformatting '$ 0'
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 8 Nov 2021 23:52:39 +0000 (15:52 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 8 Nov 2021 23:53:47 +0000 (15:53 -0800)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index f38cba873c4a65432e3bbc454caac72bfb6cdaeb..083791968757a3a63a6cab86dc291f3024d6514b 100644 (file)
@@ -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;
                     }
                 }
index d3bd2fd6e00e762083380ba79137f330e2f9df39..8f29937b1fcca6887504fe1cf95e7f671c1a19b6 100644 (file)
@@ -2,6 +2,33 @@
 
 =over 4
 
+=item B<Fix coding error, issue c104>
+
+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<Fix undefined variable reference, c102>
 
 Random testing produced an undefined variable reference for the following input