pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/pkgtools/pkglint/files Improved variable_needs_quoting.



details:   https://anonhg.NetBSD.org/pkgsrc/rev/0f3c46c1520a
branches:  trunk
changeset: 513939:0f3c46c1520a
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Tue Jun 06 06:48:16 2006 +0000

description:
Improved variable_needs_quoting.

diffstat:

 pkgtools/pkglint/files/makevars.map |   4 +-
 pkgtools/pkglint/files/pkglint.pl   |  38 +++++++++++++++++++++++++++++-------
 2 files changed, 32 insertions(+), 10 deletions(-)

diffs (90 lines):

diff -r 28ba3e93680a -r 0f3c46c1520a pkgtools/pkglint/files/makevars.map
--- a/pkgtools/pkglint/files/makevars.map       Tue Jun 06 06:44:01 2006 +0000
+++ b/pkgtools/pkglint/files/makevars.map       Tue Jun 06 06:48:16 2006 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: makevars.map,v 1.104 2006/06/05 22:24:12 rillig Exp $
+# $NetBSD: makevars.map,v 1.105 2006/06/06 06:48:16 rillig Exp $
 #
 
 # This file contains the guessed type of some variables, according to
@@ -416,7 +416,7 @@
 PERL5_PACKLIST_DIR     Pathname []
 PGSQL_VERSIONS_ACCEPTED        List of { 73 74 80 }
 PGSQL_VERSION_DEFAULT  Unchecked []
-PKGBASE                        Unchecked []
+PKGBASE                        Identifier []
 PKGCONFIG_OVERRIDE     List of Pathmask [m:as,c:a]
 PKGDIR                 RelativePkgDir
 PKGNAME                        PkgName [m:s,c:s,Makefile.*:ds,*:ds]
diff -r 28ba3e93680a -r 0f3c46c1520a pkgtools/pkglint/files/pkglint.pl
--- a/pkgtools/pkglint/files/pkglint.pl Tue Jun 06 06:44:01 2006 +0000
+++ b/pkgtools/pkglint/files/pkglint.pl Tue Jun 06 06:48:16 2006 +0000
@@ -1,5 +1,5 @@
 #! @PERL@
-# $NetBSD: pkglint.pl,v 1.603 2006/06/06 05:18:56 rillig Exp $
+# $NetBSD: pkglint.pl,v 1.604 2006/06/06 06:48:16 rillig Exp $
 #
 
 # pkglint - static analyzer and checker for pkgsrc packages
@@ -2637,6 +2637,7 @@
                PkgName
                RelativePkgDir RelativePkgPath
                URL UserGroupName
+               Version
                WrkdirSubdirectory
        ));
 
@@ -2644,17 +2645,38 @@
                return dont_know;
        }
 
+       if ($type->kind_of_list == LK_NONE && exists(safe_types->{$type->basic_type})) {
+               return doesnt_matter;
+       }
+
        # Determine whether the context expects a list of shell words or
        # not.
        $want_list = $context->type->is_practically_a_list() && ($context->shellword == VUC_SHELLWORD_BACKT || $context->extent != VUC_EXTENT_WORD_PART);
        $have_list = $type->is_practically_a_list();
 
-       if ($type->kind_of_list == LK_NONE && exists(safe_types->{$type->basic_type})) {
-               return doesnt_matter;
-       }
-
-       $opt_debug_quoting and $line->log_debug("[variable_needs_quoting] varname $varname context " . $context->to_string() . " type " . $type->to_string());
-       $opt_debug_quoting and $line->log_debug(sprintf("[%s] want_list=%d have_list=%d", "variable_needs_quoting", $want_list, $have_list));
+       $opt_debug_quoting and $line->log_debug("[variable_needs_quoting]"
+               . " varname=$varname"
+               . " context=" . $context->to_string()
+               . " type=" . $type->to_string()
+               . " want_list=" . ($want_list ? "yes" : "no")
+               . " have_list=" . ($have_list ? "yes" : "no")
+               . ".");
+
+       # Variables that appear as parts of shell words generally need
+       # to be quoted. An exception is in the case of backticks,
+       # because the whole backticks expression is parsed as a single
+       # shell word.
+       #
+       # XXX: When the shell word parser gets rewritten the next time,
+       # this test can be refined.
+       if ($context->extent == VUC_EXTENT_WORD_PART && $context->shellword != VUC_SHELLWORD_BACKT) {
+               return true;
+       }
+
+       # Assigning lists to lists does not require any quoting.
+       if ($want_list && $have_list) {
+               return false;
+       }
 
        # Appending elements to a list requires quoting, as well as
        # assigning a list value to a non-list variable.
@@ -3108,7 +3130,7 @@
        if ($shellword =~ qr"^\$\{(${regex_varname})(:[^{}]+)?\}$") {
                my ($varname, $mod) = ($1, $2);
 
-               $opt_warn_quoting and checkline_mk_varuse($line, $varname, defined($mod) ? $mod : "", shellword_vuc);
+               checkline_mk_varuse($line, $varname, defined($mod) ? $mod : "", shellword_vuc);
                return;
        }
 



Home | Main Index | Thread Index | Old Index