]> git.proxmox.com Git - pve-common.git/commitdiff
idmap followup: avoid false-negatives through falsy values in collision check
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 2 Apr 2020 15:30:55 +0000 (17:30 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 2 Apr 2020 15:33:47 +0000 (17:33 +0200)
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 <t.lamprecht@proxmox.com>
src/PVE/JSONSchema.pm

index d332a3dd1c21dbbd8c86721045005c665e4b4461..01a3cce13bff8741bf76a3e0b01c32c75cb7ecc2 100644 (file)
@@ -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;
 }