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.
This commit is contained in:
Wolfgang Bumiller 2016-07-14 09:21:24 +02:00 committed by Fabian Grünbichler
parent 123921731a
commit 88a490ff71

View File

@ -645,6 +645,9 @@ sub check_type {
return undef; return undef;
} }
return 1; 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 { } else {
if ($vt) { if ($vt) {
add_error($errors, $path, "type check ('$type') failed - got $vt"); add_error($errors, $path, "type check ('$type') failed - got $vt");