[pve-devel] [RFC common] allow Regexp objects for strings in the schema

Wolfgang Bumiller w.bumiller at proxmox.com
Thu Jul 14 09:21:24 CEST 2016


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");
-- 
2.1.4




More information about the pve-devel mailing list