]> git.proxmox.com Git - pve-common.git/blobdiff - data/PVE/Tools.pm
allow to pass undefined value to template_replace
[pve-common.git] / data / PVE / Tools.pm
index 8b2725e3aff2f718c5cef3818648865cf394d428..85b32305e85c811885c4561e68e8507ad57d94b1 100644 (file)
@@ -200,10 +200,14 @@ sub run_command {
     my ($cmd, %param) = @_;
 
     my $old_umask;
+    my $cmdstr;
 
-    $cmd = [ $cmd ] if !ref($cmd);
-
-    my $cmdstr = cmd2string($cmd);
+    if (!ref($cmd)) {
+       $cmdstr = $cmd;
+       $cmd = [ $cmd ];
+    } else {
+       $cmdstr = cmd2string($cmd);
+    }
 
     my $errmsg;
     my $laststderr;
@@ -450,6 +454,8 @@ sub trim {
 sub template_replace {
     my ($tmpl, $data) = @_;
 
+    return $tmpl if !$tmpl;
     my $res = '';
     while ($tmpl =~ m/([^{]+)?({([^}]+)})?/g) {
        $res .= $1 if $1;
@@ -723,6 +729,16 @@ sub decode_text {
     return Encode::decode("utf8", uri_unescape($data));
 }
 
+sub decode_utf8_parameters {
+    my ($param) = @_;
+
+    foreach my $p (qw(comment description firstname lastname)) {
+       $param->{$p} = decode('utf8', $param->{$p}) if $param->{$p};
+    }
+
+    return $param;
+}
+
 sub random_ether_addr {
 
     my $rand = Digest::SHA1::sha1_hex(rand(), time());