From 88a490ff71d5491b2564f4f49931e71410bed9c3 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Thu, 14 Jul 2016 09:21:24 +0200 Subject: [PATCH] allow Regexp objects for strings in the schema 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 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm index 5b5fe15..b53736e 100644 --- a/src/PVE/JSONSchema.pm +++ b/src/PVE/JSONSchema.pm @@ -645,6 +645,9 @@ sub check_type { 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");