Merge pull request #9237 from strapi/fix/9236

Fix regex validation
This commit is contained in:
ELABBASSI Hicham 2021-01-29 09:59:58 +01:00 committed by GitHub
commit 454f666b11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -212,13 +212,6 @@ const createYupSchema = (
const createYupSchemaAttribute = (type, validations, options) => {
let schema = yup.mixed();
let regex = get(validations, 'regex', null);
delete validations.regex;
if (regex) {
validations.regex = new RegExp(regex);
}
if (['string', 'uid', 'text', 'richtext', 'email', 'password', 'enumeration'].includes(type)) {
schema = yup.string();
}
@ -341,7 +334,7 @@ const createYupSchemaAttribute = (type, validations, options) => {
break;
}
case 'regex':
schema = schema.matches(validationValue, errorsTrads.regex);
schema = schema.matches(new RegExp(validationValue), errorsTrads.regex);
break;
case 'lowercase':
if (['text', 'textarea', 'email', 'string'].includes(type)) {