[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[checks/scripts] [PATCH 1/4] bashisms and "quoted quotes"



Hi,

This is the first of a series of patches updating checks/scripts
bashisms checks with some changes that have been made to checkbashisms
over the past few months.

Hopefully all the patches are self-explanatory, but please let me know
if there are any questions or issues.

Regards,

Adam

quoted-quotes.diff
------------------

Removes "quoted quotes" (i.e. "'" and '"') from strings before removing
single-quoted strings. This was added to handle this from libtool's
ltmain.sh (specifically /usr/bin/freehdl-libtool from the freehdl
package):

        && $echo "X$libobj" | grep '[]~#^*{};<>?"'"'"'        &()|`$[]'
        \

After applying the patch, the above is reduced to

         && $echo "X$libobj" | grep '[]~#^*{};<>?        &()|`$[]' \

and thus to

         && $echo "X$libobj" | grep '' \

once single-quoted strings have been removed.

Additionally, the "remove single/double quoted strings" expressions have
been updated to not treat the content of "'b'c" as a single quoted
string (and similarly for '"b"c')
--- scripts.orig	2008-06-13 10:05:06.000000000 +0100
+++ scripts	2008-06-13 10:07:06.000000000 +0100
@@ -596,7 +596,14 @@
 		# argument to grep or the like.
 		my $line = $_;
 		unless ($found) {
-		    $line =~ s/(^|[^\\](?:\\\\)*)\'(?:\\.|[^\\\'])+\'/$1''/g;
+		    # Remove "quoted quotes". They're likely to be inside
+		    # another pair of quotes; we're not interested in
+		    # them for their own sake and removing them makes finding
+		    # the limits of the outer pair far easier.
+		    $line =~ s/(^|[^\\\'\"])\"\'\"/$1/g;
+		    $line =~ s/(^|[^\\\'\"])\'\"\'/$1/g;
+
+		    $line =~ s/(^|[^\\\"](?:\\\\)*)\'(?:\\.|[^\\\'])+\'/$1''/g;
 		    for my $re (@bashism_string_regexs) {
 			if ($line =~ m/($re)/) {
 			    $found = 1;
@@ -609,7 +616,7 @@
 		# We've checked for all the things we still want to notice in
 		# double-quoted strings, so now remove those strings as well.
 		unless ($found) {
-		    $line =~ s/(^|[^\\](?:\\\\)*)\"(?:\\.|[^\\\"])+\"/$1""/g;
+		    $line =~ s/(^|[^\\\'](?:\\\\)*)\"(?:\\.|[^\\\"])+\"/$1""/g;
 		    for my $re (@bashism_regexs) {
 			if ($line =~ m/($re)/) {
 			    $found = 1;

Reply to: