]> git.proxmox.com Git - pve-common.git/commitdiff
allow Regexp objects for strings in the schema
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 14 Jul 2016 07:21:24 +0000 (09:21 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Thu, 14 Jul 2016 08:28:57 +0000 (10:28 +0200)
The 'pattern' property has type string and format regex, so
it makes sense to allow Regexp objects to be used for it.

While check_type() doesn't know the format, Regexp objects
can be treated like strings anyway, including compared via
'eq' or matched via '=~', so we allow strings to generally
come from a Regexp object.

src/PVE/JSONSchema.pm

index 5b5fe1568a234a3c89832d2dba825c38be243952..b53736e4c63b0ec9975e2b385defcb71229e8597 100644 (file)
@@ -645,6 +645,9 @@ sub check_type {
                return undef;
            }
            return 1;
                return undef;
            }
            return 1;
+       } elsif ($type eq 'string' && $vt eq 'Regexp') {
+           # qr// regexes can be used as strings and make sense for format=regex
+           return 1;
        } else {
            if ($vt) {
                add_error($errors, $path, "type check ('$type') failed - got $vt");
        } else {
            if ($vt) {
                add_error($errors, $path, "type check ('$type') failed - got $vt");