[pve-devel] [RFC common] allow Regexp objects for strings in the schema
Fabian Grünbichler
f.gruenbichler at proxmox.com
Thu Jul 14 11:23:21 CEST 2016
applied
On Thu, Jul 14, 2016 at 09:21:24AM +0200, Wolfgang Bumiller wrote:
> 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
>
>
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
>
More information about the pve-devel
mailing list