Subject: [PATCH 09/18] checkbashisms: fix handling of # characters in quoted strings

From: Raphael Geissert <[email-masked]>
Date: Mon, 22 Oct 2012 01:48:25 -0500

The code that removes comments wasn't taking into consideration open,
multi-line, quoted strings. In some cases it could remove the closing
quote character because it considered it to be part of a comment.

Signed-off-by: Raphael Geissert <[email-masked]>
---
 scripts/checkbashisms.pl |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/scripts/checkbashisms.pl b/scripts/checkbashisms.pl
index 975f710..c5ec676 100755
--- a/scripts/checkbashisms.pl
+++ b/scripts/checkbashisms.pl
@@ -183,6 +183,12 @@ foreach my $filename (@ARGV) {
 	s/(^|[^\\](?:\\\\)*)\'(?:\\.|[^\\\'])+\'/$1''/g;
 	s/(^|[^\\](?:\\\\)*)\"(?:\\.|[^\\\"])+\"/$1""/g;
 
+	# If inside a quoted string, remove everything before the quote
+	s/^.+?\'//
+	    if ($quote_string eq "'");
+	s/^.+?[^\\]\"//
+	    if ($quote_string eq '"');
+
 	# If the remaining string contains what looks like a comment,
 	# eat it. In either case, swap the unmodified script line
 	# back in for processing.
-- 
1.7.10