Subject: [PATCH 2/2] checkbashisms: fix multiple quotes-handling bugs

From: Raphael Geissert <[email-masked]>
Date: Tue, 25 May 2010 00:45:52 -0500

Signed-off-by: Raphael Geissert <[email-masked]>
---
 scripts/checkbashisms.pl |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/scripts/checkbashisms.pl b/scripts/checkbashisms.pl
index 65800eb..8cec53d 100755
--- a/scripts/checkbashisms.pl
+++ b/scripts/checkbashisms.pl
@@ -156,7 +156,10 @@ foreach my $filename (@ARGV) {
 	# will be treated as part of the comment.
 	# s/^(?:.*?[^\\])?$quote_string(.*)$/$1/ if $quote_string ne "";
 
-	next if m,^\s*\#,;  # skip comment lines
+	# skip comment lines
+	if (m,^\s*\#, && $quote_string eq '' && $buffered_line eq '' && $cat_string eq '') {
+	    next;
+	}
 
 	# Remove quoted strings so we can more easily ignore comments
 	# inside them
@@ -278,7 +281,7 @@ foreach my $filename (@ARGV) {
 		    my $otherquote = ($quote eq "\"" ? "\'" : "\"");
 
 		    # Remove balanced quotes and their content
-		    $templine =~ s/(^|[^\\\"](?:\\\\)*)\'(?:\\.|[^\\\'])+\'/$1/g;
+		    $templine =~ s/(^|[^\\\"](?:\\\\)*)\'[^\']*\'/$1/g;
 		    $templine =~ s/(^|[^\\\'](?:\\\\)*)\"(?:\\.|[^\\\"])+\"/$1/g;
 
 		    # Don't flag quotes that are themselves quoted
@@ -286,6 +289,8 @@ foreach my $filename (@ARGV) {
 		    $templine =~ s/$otherquote.*?$quote.*?$otherquote//g;
 		    # "\""
 		    $templine =~ s/(^|[^\\])$quote\\$quote$quote/$1/g;
+		    # \' or \"
+		    $templine =~ s/\\[\'\"]//g;
 		    my $count = () = $templine =~ /(^|(?!\\))$quote/g;
 
 		    # If there's an odd number of non-escaped
@@ -397,7 +402,6 @@ foreach my $filename (@ARGV) {
             }
 	}
     }
-
     close C;
 }
 
-- 
1.7.1