summaryrefslogtreecommitdiff
path: root/Debian/Debhelper
diff options
context:
space:
mode:
authorjoey <joey>2001-05-29 22:24:20 +0000
committerjoey <joey>2001-05-29 22:24:20 +0000
commita524668098e5215a64ac4cc466b3de6590d13cfe (patch)
tree277495c22fc3c42b5980e85c069cc1e2e9818bb1 /Debian/Debhelper
parentc9c53916d94447ed7b33a6c1956142081071c206 (diff)
r472: * Fixed issues with extended parameters to dh_gencontrol including spaces
and quotes. This was some histirical cruft that deals with splitting up the string specified by -u, and it should not have applied to the set of options after --. Now that it's fixed, any and all programs that support a -- and options after it, do not require any special quoting of the succeeding options. Quote just like you would in whatever program those options go to. So, for example, dh_gencontrol -Vblah:Depends='foo, bar (>= 1.2)' will work just as you would hope. This fix does NOT apply to -u; don't use -u if you must do something complex. Closes: #89311 * Made escape_shell output a lot better.
Diffstat (limited to 'Debian/Debhelper')
-rw-r--r--Debian/Debhelper/Dh_Getopt.pm13
-rw-r--r--Debian/Debhelper/Dh_Lib.pm41
2 files changed, 37 insertions, 17 deletions
diff --git a/Debian/Debhelper/Dh_Getopt.pm b/Debian/Debhelper/Dh_Getopt.pm
index 6d545e36..191227da 100644
--- a/Debian/Debhelper/Dh_Getopt.pm
+++ b/Debian/Debhelper/Dh_Getopt.pm
@@ -177,10 +177,17 @@ sub parseopts {
error("I have no package to build");
}
+ if (defined $options{U_PARAMS}) {
+ # Split the U_PARAMS up into an array.
+ my $u=$options{U_PARAMS};
+ undef $options{U_PARAMS};
+ push @{$options{U_PARAMS}}, split(/\s+/,$u);
+ }
+
# Anything left in @ARGV is options that appeared after a --
- # These options are added to U_PARAMS, while the non-option
- # values we collected replace them in @ARGV;
- $options{U_PARAMS}.=join(' ', @ARGV);
+ # These options are added to the U_PARAMS array, while the
+ # non-option values we collected replace them in @ARGV;
+ push @{$options{U_PARAMS}}, @ARGV;
@ARGV=@{$options{ARGV}} if exists $options{ARGV};
return %options;
diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm
index 6185e19c..92eae0c7 100644
--- a/Debian/Debhelper/Dh_Lib.pm
+++ b/Debian/Debhelper/Dh_Lib.pm
@@ -75,21 +75,34 @@ sub init {
# This package gets special treatement: files and directories specified on
# the command line may affect it.
$dh{FIRSTPACKAGE}=${$dh{DOPACKAGES}}[0];
-
- # Split the U_PARAMS up into an array.
- my $u=$dh{U_PARAMS};
- undef $dh{U_PARAMS};
- if (defined $u) {
- push @{$dh{U_PARAMS}}, split(/\s+/,$u);
- }
}
-# Escapes out shell metacharacters in a line of shell script.
+# Pass it an array containing the arguments of a shell command like would
+# be run by exec(). It turns that into a line like you might enter at the
+# shell, escaping metacharacters and quoting qrguments that contain spaces.
sub escape_shell {
- my $line=shift;
- # This list is from _Unix in a Nutshell_. (except '#')
- $line=~s/([\s!"\$()*+#;<>?@\[\]\\`|~])/\\$1/g;
- return $line;
+ my @args=@_;
+ my $line="";
+ my @ret;
+ foreach my $word (@args) {
+ if ($word=~/\s/) {
+ # Escape only a few things since it will be quoted.
+ # Note we use double quotes because you cannot
+ # escape ' in qingle quotes, while " can be escaped
+ # in double.
+ # This does make -V"foo bar" turn into "-Vfoo bar",
+ # but that will be parsed identically by the shell
+ # anyway..
+ $word=~s/([\n`\$"\\])/\$1/g;
+ push @ret, "\"$word\"";
+ }
+ else {
+ # This list is from _Unix in a Nutshell_. (except '#')
+ $word=~s/([\s!"\$()*+#;<>?@\[\]\\`|~])/\\$1/g;
+ push @ret,$word;
+ }
+ }
+ return join(' ', @ret);
}
# Run a command, and display the command to stdout if verbose mode is on.
@@ -99,8 +112,8 @@ sub escape_shell {
# Note that this cannot handle complex commands, especially anything
# involving redirection. Use complex_doit instead.
sub doit {
- verbose_print(join(" ",map { escape_shell($_) } @_));
-
+ verbose_print(escape_shell(@_));
+
if (! $dh{NO_ACT}) {
system(@_) == 0 || error("command returned error code");
}