[SCM] Git repository for devscripts branch, master, updated. v2.12.4-43-g227b8b8
Benjamin Drung
bdrung at debian.org
Thu Oct 25 20:17:04 UTC 2012
The following commit has been merged in the master branch:
commit f76701912665acf1ded2b20b1b696825a02ddffb
Author: Raphael Geissert <geissert at debian.org>
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 <bdrung at debian.org>
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
More information about the devscripts-devel
mailing list