From bc6da2b006e2e1e3133c44d603fd84ad2deec2de Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sat, 3 Nov 2012 14:48:14 +0000 Subject: [PATCH] scstadmin: Allow hash signs to be escaped (merge r4391 from trunk) git-svn-id: http://svn.code.sf.net/p/scst/svn/branches/2.2.x@4592 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/scstadmin.sysfs/scstadmin | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/scstadmin/scstadmin.sysfs/scstadmin b/scstadmin/scstadmin.sysfs/scstadmin index 9941b5c67..bb1bb7ec9 100755 --- a/scstadmin/scstadmin.sysfs/scstadmin +++ b/scstadmin/scstadmin.sysfs/scstadmin @@ -1247,6 +1247,17 @@ sub readWorkingConfig { return FALSE; } +# Escape metacharacters (space, backslash and hash sign). +sub escapeMeta { + my $value = shift; + + $value =~ s/([\\\#])/\\\1/g; + if ($value =~ / /) { + $value = "\"$value\""; + } + return $value; +} + # Serialize key attributes. # $prefix: output prefix, e.g. "\t\t". # $attributes: reference to a hash with attributes and their values. @@ -1269,10 +1280,7 @@ sub serializeKeyAttr { my $value = $$attributes{$attribute}->{'keys'}->{$key}->{'value'}; if ($value ne '') { - if ($value =~ / /) { - $value = "\"$value\""; - } - $result .= "$prefix$attribute $value\n"; + $result .= "$prefix$attribute " . escapeMeta($value) . "\n"; } } } elsif ($attribute eq 'enabled' || $attribute eq 'hw_target') { @@ -1305,10 +1313,7 @@ sub serializeNkAttr { && $attribute ne 'hw_target') { my $value = $$attributes{$attribute}->{'value'}; if ($value ne '') { - if ($value =~ / /) { - $value = "\"$value\""; - } - $result .= "$prefix$attribute $value\n"; + $result .= "$prefix$attribute " . escapeMeta($value) . "\n"; } } } @@ -5056,7 +5061,8 @@ sub readConfigFile { if (!$io); while (my $line = <$io>) { - ($line, undef) = split(/\#/, $line, 2); + $line =~ s/^\#.*//; + $line =~ s/[^\\]\#.*//; if ($line =~ /\[(.*)\s+.*\]/) { my $parm = $1; @@ -5069,6 +5075,7 @@ sub readConfigFile { } } + $line =~ s/\\(.)/\1/g; $buffer .= $line; }