lintian: r1390 - in trunk: checks debian testset testset/maintainer-scripts/debian
Author: djpig
Date: 2008-06-17 22:42:46 +0200 (Tue, 17 Jun 2008)
New Revision: 1390
Modified:
trunk/checks/scripts
trunk/debian/changelog
trunk/testset/maintainer-scripts/debian/postinst
trunk/testset/tags.maintainer-scripts
Log:
* checks/scripts:
+ Improve heredoc detection. Patch by Adam D. Barratt.
Modified: trunk/checks/scripts
===================================================================
--- trunk/checks/scripts 2008-06-17 20:06:53 UTC (rev 1389)
+++ trunk/checks/scripts 2008-06-17 20:42:46 UTC (rev 1390)
@@ -531,7 +531,7 @@
}
if ($shellscript) {
- if ($cat_string ne "" and m/^$cat_string/) {
+ if ($cat_string ne "" and m/^\Q$cat_string\E$/) {
$cat_string = "";
}
my $within_another_shell = 0;
@@ -596,6 +596,25 @@
# Ignore anything inside single quotes; it could be an
# argument to grep or the like.
my $line = $_;
+
+ # $cat_line contains the version of the line we'll check
+ # for heredoc delimiters later. Initially, remove any
+ # spaces between << and the delimiter to make the following
+ # updates to $cat_line easier.
+ my $cat_line = $line;
+ $cat_line =~ s/(<\<-?)\s+/$1/g;
+
+ my $sq_string_with_prefix = qr"(^|[^<\\\"-](?:\\\\)*)\'(?:\\.|[^\\\'])+\'";
+ my $dq_string_with_prefix = qr"(^|[^<\\\'-](?:\\\\)*)\"(?:\\.|[^\\\"])+\"";
+
+ # Remove single quoted strings, with the exception that we
+ # don't remove the string
+ # if the quote is immediately preceeded by a < or a -, so we
+ # can match "foo <<-?'xyz'" as a heredoc later
+ # The check is a little more greedy than we'd like, but the
+ # heredoc test itself will weed out any false positives
+ $cat_line =~ s/$sq_string_with_prefix/$1''/g;
+
unless ($found) {
# Remove "quoted quotes". They're likely to be inside
# another pair of quotes; we're not interested in
@@ -604,7 +623,7 @@
$line =~ s/(^|[^\\\'\"])\"\'\"/$1/g;
$line =~ s/(^|[^\\\'\"])\'\"\'/$1/g;
- $line =~ s/(^|[^\\\"](?:\\\\)*)\'(?:\\.|[^\\\'])+\'/$1''/g;
+ $line =~ s/$sq_string_with_prefix/$1''/g;
for my $re (@bashism_string_regexs) {
if ($line =~ m/($re)/) {
$found = 1;
@@ -616,8 +635,9 @@
# We've checked for all the things we still want to notice in
# double-quoted strings, so now remove those strings as well.
+ $cat_line =~ s/$dq_string_with_prefix/$1""/g;
unless ($found) {
- $line =~ s/(^|[^\\\'](?:\\\\)*)\"(?:\\.|[^\\\"])+\"/$1""/g;
+ $line =~ s/$dq_string_with_prefix/$1""/g;
for my $re (@bashism_regexs) {
if ($line =~ m/($re)/) {
$found = 1;
@@ -633,8 +653,9 @@
# Only look for the beginning of a heredoc here, after we've
# stripped out quoted material, to avoid false positives.
- if (m/(?:^|[^<])\<\<\s*[\'\"]?(\w+)[\'\"]?/) {
+ if ($cat_line =~ m/(?:^|[^<])\<\<\-?\s*(?:[\\]?(\w+)|[\'\"](.*?)[\'\"])/) {
$cat_string = $1;
+ $cat_string = $2 if not defined $cat_string;
}
}
if (!$cat_string) {
Modified: trunk/debian/changelog
===================================================================
--- trunk/debian/changelog 2008-06-17 20:06:53 UTC (rev 1389)
+++ trunk/debian/changelog 2008-06-17 20:42:46 UTC (rev 1390)
@@ -17,6 +17,7 @@
them for their own sake and removing them makes finding
the limits of the outer pair far easier. Patch by
Adam D. Barratt.
+ + [FL] Improve heredoc detection. Patch by Adam D. Barratt.
* checks/watch-file{,.desc}:
+ [FL] Check for more Debian specific strings in version
number. Issue an info tag if the watch file uses
Modified: trunk/testset/maintainer-scripts/debian/postinst
===================================================================
--- trunk/testset/maintainer-scripts/debian/postinst 2008-06-17 20:06:53 UTC (rev 1389)
+++ trunk/testset/maintainer-scripts/debian/postinst 2008-06-17 20:42:46 UTC (rev 1390)
@@ -104,10 +104,37 @@
EOF
# But this isn't.
-cat '>>EOF'
+cat '<<EOF'
echo "All of the array is: ${H[@]}"
EOF
+# This is a heredoc
+cat <<-EOF
+echo "All of the arry is ${H[@]}"
+EOF
+
+# As is this
+cat <<';'
+echo "All of the array is ${H[@]}"
+;
+
+# and this
+cat <<foo
+echo "All of the array is ${H[@]}"
+foobar
+echo $HOSTNAME
+foo
+
+# and again
+cat <<\bar
+echo "All of the array is ${H[@]}"
+bar
+
+# yet another
+cat <<"x++"
+echo "All of the array is ${H[@]}"
+x++
+
# Recognize single quotes even if they start at the beginning of a line.
echo not a bashism \
'/{ptex,tex}/{amstex,plain,generic,}'
Modified: trunk/testset/tags.maintainer-scripts
===================================================================
--- trunk/testset/tags.maintainer-scripts 2008-06-17 20:06:53 UTC (rev 1389)
+++ trunk/testset/tags.maintainer-scripts 2008-06-17 20:42:46 UTC (rev 1390)
@@ -37,7 +37,7 @@
W: maintainer-scripts: ancient-dpkg-multi-conrep-check preinst:10
W: maintainer-scripts: ancient-dpkg-predepends-check preinst:7
W: maintainer-scripts: config-does-not-load-confmodule
-W: maintainer-scripts: deprecated-chown-usage postinst:138 'chown -R root.root'
+W: maintainer-scripts: deprecated-chown-usage postinst:165 'chown -R root.root'
W: maintainer-scripts: deprecated-chown-usage postinst:33 'chown root.root'
W: maintainer-scripts: gconftool-used-in-maintainer-script postinst:68
W: maintainer-scripts: init.d-script-not-marked-as-conffile /etc/init.d/foo
@@ -50,16 +50,16 @@
W: maintainer-scripts: missing-debconf-dependency
W: maintainer-scripts: no-debconf-templates
W: maintainer-scripts: possible-bashism-in-maintainer-script postinst:108 '${H[@]}'
-W: maintainer-scripts: possible-bashism-in-maintainer-script postinst:116 'echo -e'
-W: maintainer-scripts: possible-bashism-in-maintainer-script postinst:117 '${!foo}'
-W: maintainer-scripts: possible-bashism-in-maintainer-script postinst:119 'select foo'
-W: maintainer-scripts: possible-bashism-in-maintainer-script postinst:122 ' exec -l'
-W: maintainer-scripts: possible-bashism-in-maintainer-script postinst:123 ' exec -c'
-W: maintainer-scripts: possible-bashism-in-maintainer-script postinst:124 ' exec -a'
-W: maintainer-scripts: possible-bashism-in-maintainer-script postinst:126 'let '
-W: maintainer-scripts: possible-bashism-in-maintainer-script postinst:127 'test -a'
-W: maintainer-scripts: possible-bashism-in-maintainer-script postinst:128 '$RANDOM'
+W: maintainer-scripts: possible-bashism-in-maintainer-script postinst:143 'echo -e'
+W: maintainer-scripts: possible-bashism-in-maintainer-script postinst:144 '${!foo}'
+W: maintainer-scripts: possible-bashism-in-maintainer-script postinst:146 'select foo'
+W: maintainer-scripts: possible-bashism-in-maintainer-script postinst:149 ' exec -l'
W: maintainer-scripts: possible-bashism-in-maintainer-script postinst:15 '. /usr/share/lintian/shell foo'
+W: maintainer-scripts: possible-bashism-in-maintainer-script postinst:150 ' exec -c'
+W: maintainer-scripts: possible-bashism-in-maintainer-script postinst:151 ' exec -a'
+W: maintainer-scripts: possible-bashism-in-maintainer-script postinst:153 'let '
+W: maintainer-scripts: possible-bashism-in-maintainer-script postinst:154 'test -a'
+W: maintainer-scripts: possible-bashism-in-maintainer-script postinst:155 '$RANDOM'
W: maintainer-scripts: possible-bashism-in-maintainer-script postinst:18 'read'
W: maintainer-scripts: possible-bashism-in-maintainer-script postinst:20 'H[0]='
W: maintainer-scripts: possible-bashism-in-maintainer-script postinst:21 '${H[0]}'
@@ -79,5 +79,5 @@
W: maintainer-scripts: postrm-does-not-purge-debconf
W: maintainer-scripts: postrm-has-useless-call-to-ldconfig
W: maintainer-scripts: read-in-maintainer-script postinst:18
-W: maintainer-scripts: start-stop-daemon-in-maintainer-script postinst:132
+W: maintainer-scripts: start-stop-daemon-in-maintainer-script postinst:159
W: maintainer-scripts: update-alternatives-remove-called-in-postrm
Reply to: