From: Thomas Lamprecht Date: Thu, 2 Apr 2020 15:30:55 +0000 (+0200) Subject: idmap followup: avoid false-negatives through falsy values in collision check X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=commitdiff_plain;h=e12df964dccfffe781eeee489347719d638b91a4 idmap followup: avoid false-negatives through falsy values in collision check By using "exists" when checking if a hash entry is set, else things like "0" could get accepted by mistake. Also cleanup the code a little, like dropping the "PVE::JSONSchema::" prefix, this is now in that module after all. Signed-off-by: Thomas Lamprecht --- diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm index d332a3d..01a3cce 100644 --- a/src/PVE/JSONSchema.pm +++ b/src/PVE/JSONSchema.pm @@ -235,33 +235,30 @@ sub parse_idmap { } elsif ($entry =~ m/^([^:]+):([^:]+)$/) { my ($source, $target) = ($1, $2); eval { - PVE::JSONSchema::check_format($idformat, $source, ''); - PVE::JSONSchema::check_format($idformat, $target, ''); + check_format($idformat, $source, ''); + check_format($idformat, $target, ''); }; - die "entry '$entry' contains invalid ID - $@\n" - if $@; + die "entry '$entry' contains invalid ID - $@\n" if $@; die "duplicate mapping for source '$source'\n" - if $map->{entries}->{$source}; + if exists $map->{entries}->{$source}; $map->{entries}->{$source} = $target; } else { eval { - PVE::JSONSchema::check_format($idformat, $entry); + check_format($idformat, $entry); }; - - die "entry '$entry' contains invalid ID - $@\n" - if $@; + die "entry '$entry' contains invalid ID - $@\n" if $@; die "default target ID can only be provided once\n" - if $map->{default}; + if exists $map->{default}; $map->{default} = $entry; } } die "identity mapping cannot be combined with other mappings\n" - if $map->{identity} && ($map->{default} || $map->{entries}); + if $map->{identity} && ($map->{default} || exists $map->{entries}); return $map; }