summaryrefslogtreecommitdiffstats
path: root/MDK/Common/System.pm
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2004-06-28 08:01:52 +0000
committerPascal Rigaux <pixel@mandriva.com>2004-06-28 08:01:52 +0000
commiteb7b9f404f2405a1cb152fac39101200ec3b9d98 (patch)
tree5563fd19852d64ebfb00af5c77c98ef60808770f /MDK/Common/System.pm
parente2b6da2c1858c657ebd527fcf64e08bce41746cc (diff)
downloadperl-MDK-Common-eb7b9f404f2405a1cb152fac39101200ec3b9d98.tar
perl-MDK-Common-eb7b9f404f2405a1cb152fac39101200ec3b9d98.tar.gz
perl-MDK-Common-eb7b9f404f2405a1cb152fac39101200ec3b9d98.tar.bz2
perl-MDK-Common-eb7b9f404f2405a1cb152fac39101200ec3b9d98.tar.xz
perl-MDK-Common-eb7b9f404f2405a1cb152fac39101200ec3b9d98.zip
- fix single/quote handling in getVarsFromSh()
- setVarsInSh() now handles characters $, ', " and spaces in the value
Diffstat (limited to 'MDK/Common/System.pm')
-rw-r--r--MDK/Common/System.pm29
1 files changed, 17 insertions, 12 deletions
diff --git a/MDK/Common/System.pm b/MDK/Common/System.pm
index af96481..22894b3 100644
--- a/MDK/Common/System.pm
+++ b/MDK/Common/System.pm
@@ -307,17 +307,10 @@ sub getVarsFromSh {
local $_;
while (<$F>) {
s/#.*//; # remove comments
- my ($v, $val, $val2) =
- /^\s* # leading space
- (\w+) = # variable
- (
- "([^"]*)" # double-quoted text
- | '([^']*)' # single-quoted text
- | [^'"\s]+ # normal text
- )
- \s*$ # end of line
- /x or next;
- $l{$v} = defined $val2 ? $val2 : $val;
+ s/^\s*//; # leading space
+ my ($v, $val) = /^(\w+)=(.*)/ or next;
+ $val = $1 if $val =~ /^"(.*)"$/ || $val =~ /^'(.*)'$/;
+ $l{$v} = $val;
}
%l;
}
@@ -332,7 +325,19 @@ sub setVarsInShMode {
@fields = keys %$l unless @fields;
MDK::Common::File::output($file,
- map { $l->{$_} ? "$_=$l->{$_}\n" : () } @fields
+ map {
+ my $val = $l->{$_};
+ if ($val =~ /\W/) {
+ if ($val =~ /["\$]/) {
+ $val =~ s/(')/\\$1/;
+ $val = qq('$val');
+ } else {
+ $val =~ s/(")/\\$1/;
+ $val = qq("$val");
+ }
+ }
+ "$_=$val\n";
+ } grep { $l->{$_} } @fields
);
chmod $mod, $file;
}