The following commit has been merged in the master branch:
commit f76701912665acf1ded2b20b1b696825a02ddffb
Author: Raphael Geissert <[email protected]>
Date:   Sun Oct 21 00:19:30 2012 -0500

    checkbashisms: simplify mixed single/double balanced quotes correctly
    
    Code like "'"'"'"'" was incorrectly simplified as ''" and then to just ",
    making it believe a string was being opened.
    
    Signed-off-by: Benjamin Drung <[email protected]>

diff --git a/scripts/checkbashisms.pl b/scripts/checkbashisms.pl
index 9ebc3f7..52f72b8 100755
--- a/scripts/checkbashisms.pl
+++ b/scripts/checkbashisms.pl
@@ -298,8 +298,26 @@ foreach my $filename (@ARGV) {
                    my $otherquote = ($quote eq "\"" ? "\'" : "\"");
 
                    # Remove balanced quotes and their content
-                   $templine =~ s/(^|[^\\\"](?:\\\\)*)\'[^\']*\'/$1/g;
-                   $templine =~ 
s/(^|[^\\\'](?:\\\\)*)\"(?:\\.|[^\\\"])+\"/$1/g;
+                   while (1) {
+                       my ($length_single, $length_double) = (0, 0);
+
+                       # Determine which one would match first:
+                       if ($templine =~ 
m/(^.+?(?:^|[^\\\"](?:\\\\)*)\')[^\']*\'/) {
+                           $length_single = length($1);
+                       }
+                       if ($templine =~ 
m/(^.*?(?:^|[^\\\'](?:\\\\)*)\")(?:\\.|[^\\\"])+\"/) {
+                           $length_double = length($1);
+                       }
+
+                       # Now simplify accordingly (shorter is preferred):
+                       if ($length_single != 0 && ($length_single < 
$length_double || $length_double == 0)) {
+                           $templine =~ s/(^|[^\\\"](?:\\\\)*)\'[^\']*\'/$1/;
+                       } elsif ($length_double != 0) {
+                           $templine =~ 
s/(^|[^\\\'](?:\\\\)*)\"(?:\\.|[^\\\"])+\"/$1/;
+                       } else {
+                           last;
+                       }
+                   }
 
                    # Don't flag quotes that are themselves quoted
                    # "a'b"

-- 
Git repository for devscripts

_______________________________________________
devscripts-devel mailing list
[email protected]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/devscripts-devel

Reply via email to