[pve-devel] [PATCH common 2/2] schema: check format: parse list formats as arrays

Fabian Ebner f.ebner at proxmox.com
Thu Mar 18 09:44:18 CET 2021


Previously, the returned value would be only the last element or undef in case
of an empty list. There's only a handful of callers of check_format() that look
at the return value and AFAICT none of the exisitng ones is for a -list format.
But best to avoid any future surprises.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 src/PVE/JSONSchema.pm | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
index e9d10da..0586105 100644
--- a/src/PVE/JSONSchema.pm
+++ b/src/PVE/JSONSchema.pm
@@ -709,9 +709,10 @@ sub check_format {
 	if $format_type ne 'none' && ref($registered) ne 'CODE';
 
     if ($format_type eq 'list') {
+	$parsed = [];
 	# Note: we allow empty lists
 	foreach my $v (split_list($value)) {
-	    $parsed = $registered->($v);
+	    push @{$parsed}, $registered->($v);
 	}
     } elsif ($format_type eq 'opt') {
 	$parsed = $registered->($value) if $value;
-- 
2.20.1






More information about the pve-devel mailing list