X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=src%2FPVE%2FJSONSchema.pm;h=0603f7601fb6a40f138a82a59824a2a07ed57287;hb=53c255218ebec327f881a479a7be1e04646ae2e9;hp=817ff4cce51e210af3f92207fc91497ee18324b5;hpb=303a9b34ea148644e2393a11452271b4c708a7c5;p=pve-common.git diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm index 817ff4c..0603f76 100644 --- a/src/PVE/JSONSchema.pm +++ b/src/PVE/JSONSchema.pm @@ -137,7 +137,7 @@ register_format('pve-vmid', \&pve_verify_vmid); sub pve_verify_vmid { my ($vmid, $noerr) = @_; - if ($vmid !~ m/^[1-9][0-9]+$/) { + if ($vmid !~ m/^[1-9][0-9]{2,8}$/) { return undef if $noerr; die "value does not look like a valid VM ID\n"; } @@ -248,7 +248,7 @@ register_format('CIDRv4', \&pve_verify_cidrv4); sub pve_verify_cidrv4 { my ($cidr, $noerr) = @_; - if ($cidr =~ m!^(?:$IPV4RE)(?:/(\d+))$! && ($1 > 7) && ($1 < 32)) { + if ($cidr =~ m!^(?:$IPV4RE)(?:/(\d+))$! && ($1 > 7) && ($1 <= 32)) { return $cidr; } @@ -488,7 +488,10 @@ sub format_size { }; sub parse_property_string { - my ($format, $data, $path) = @_; + my ($format, $data, $path, $additional_properties) = @_; + + # In property strings we default to not allowing additional properties + $additional_properties = 0 if !defined($additional_properties); my $default_key; @@ -522,13 +525,14 @@ sub parse_property_string { die "duplicate key in comma-separated list property: $default_key\n"; } } + die "value without key, but schema does not define a default key\n" if !$default_key; } else { die "missing key in comma-separated list property\n"; } } my $errors = {}; - check_object($path, $format, $res, undef, $errors); + check_object($path, $format, $res, $additional_properties, $errors); if (scalar(%$errors)) { raise "format error\n", errors => $errors; } @@ -582,12 +586,13 @@ sub print_property_string { } foreach my $key (sort keys %$data) { - die "invalid key: $key" if !$allowed{$key}; delete $required{$key}; next if $skipped{$key}; + die "invalid key: $key" if !$allowed{$key}; my $typeformat = $format->{$key}->{format}; my $value = $data->{$key}; + next if !defined($value); $text .= $comma; $comma = ','; if ($typeformat && $typeformat eq 'disk-size') {