pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/pkgtools/pkglint/files In shell commands, handle backt...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/68934b5dc7f2
branches:  trunk
changeset: 535091:68934b5dc7f2
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Wed Nov 07 16:42:56 2007 +0000

description:
In shell commands, handle backticks inside double quotes. By the way,
double quotes inside backticks inside double quotes are error prone.

diffstat:

 pkgtools/pkglint/files/pkglint.pl |  20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)

diffs (60 lines):

diff -r ca90976f763c -r 68934b5dc7f2 pkgtools/pkglint/files/pkglint.pl
--- a/pkgtools/pkglint/files/pkglint.pl Wed Nov 07 16:29:49 2007 +0000
+++ b/pkgtools/pkglint/files/pkglint.pl Wed Nov 07 16:42:56 2007 +0000
@@ -1,5 +1,5 @@
 #! @PERL@
-# $NetBSD: pkglint.pl,v 1.731 2007/11/07 16:19:01 rillig Exp $
+# $NetBSD: pkglint.pl,v 1.732 2007/11/07 16:42:56 rillig Exp $
 #
 
 # pkglint - static analyzer and checker for pkgsrc packages
@@ -4181,7 +4181,7 @@
                # reasonable to check the whole shell command
                # recursively, instead of splitting off the first
                # make(1) variable (see the elsif below).
-               if ($state == SWST_BACKT) {
+               if ($state == SWST_BACKT || $state == SWST_DQUOT_BACKT) {
 
                        # Scan for the end of the backticks, checking
                        # for single backslashes and removing one level
@@ -4193,19 +4193,29 @@
                        my $stripped = "";
                        while ($rest ne "") {
                                if ($rest =~ s/^\`//) {
-                                       last;
+                                       $state = ($state == SWST_BACKT) ? SWST_PLAIN : SWST_DQUOT;
+                                       goto end_of_backquotes;
                                } elsif ($rest =~ s/^\\([\\\`\$])//) {
                                        $stripped .= $1;
                                } elsif ($rest =~ s/^(\\)//) {
                                        $line->log_warning("Backslashes should be doubled inside backticks.");
                                        $stripped .= $1;
+                               } elsif ($state == SWST_DQUOT_BACKT && $rest =~ s/^"//) {
+                                       $line->log_warning("Double quotes inside backticks inside double quotes are error prone.");
+                                       $line->explain_warning(
+"According to the SUSv3, they produce undefined results.",
+"",
+"See the paragraph starting \"Within the backquoted ...\" in",
+"http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html";);
                                } elsif ($rest =~ s/^([^\\\`]+)//) {
                                        $stripped .= $1;
                                } else {
                                        assert(false, "rest=$rest");
                                }
                        }
-
+                       $line->log_error("Unfinished backquotes: rest=$rest");
+
+               end_of_backquotes:
                        # Check the resulting command.
                        checkline_mk_shelltext($line, $stripped);
 
@@ -4325,6 +4335,8 @@
                } elsif ($state == SWST_DQUOT) {
                        if ($rest =~ s/^\"//) {
                                $state = SWST_PLAIN;
+                       } elsif ($rest =~ s/^\`//) {
+                               $state = SWST_DQUOT_BACKT;
                        } elsif ($rest =~ s/^[^\$"\\\`]+//) {
                        } elsif ($rest =~ s/^\\(?:[\\\"\`]|\$\$)//) {
                        } elsif ($rest =~ s/^\$\$\{([0-9A-Za-z_]+)\}//



Home | Main Index | Thread Index | Old Index