]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/JSONSchema.pm
get_options: handle array and scalar refs on decoding
[pve-common.git] / src / PVE / JSONSchema.pm
index 9c624f694c6f423ee643ef025620c369b713f5bb..921dbb5000d2fb8c6bbc35d8621268dfbd66dddf 100644 (file)
@@ -1351,8 +1351,21 @@ sub get_options {
        }
     }
 
+    # decode after Getopt as we are not sure how well it handles unicode
     foreach my $p (keys %$opts) {
-       $opts->{$p} = decode('locale', $opts->{$p});
+       if (!ref($opts->{$p})) {
+           $opts->{$p} = decode('locale', $opts->{$p});
+       } elsif (ref($opts->{$p}) eq 'ARRAY') {
+           my $tmp = [];
+           foreach my $v (@{$opts->{$p}}) {
+               push @$tmp, decode('locale', $v);
+           }
+           $opts->{$p} = $tmp;
+       } elsif (ref($opts->{$p}) eq 'SCALAR') {
+           $opts->{$p} = decode('locale', $$opts->{$p});
+       } else {
+           raise("decoding options failed, unknown reference\n", code => HTTP_BAD_REQUEST);
+       }
     }
 
     foreach my $p (keys %$opts) {