mirror of
https://github.com/strapi/strapi.git
synced 2025-09-06 15:22:59 +00:00
Update enum regex
This commit is contained in:
parent
03b22b5958
commit
985c67c057
@ -35,6 +35,7 @@ const validators = {
|
||||
};
|
||||
|
||||
const NAME_REGEX = new RegExp('^[A-Za-z][_0-9A-Za-z]*$');
|
||||
const ENUM_REGEX = new RegExp('^[_A-Za-z][_0-9A-Za-z]*$');
|
||||
|
||||
const isValidName = {
|
||||
name: 'isValidName',
|
||||
@ -48,11 +49,19 @@ const isValidKey = key => ({
|
||||
test: () => NAME_REGEX.test(key),
|
||||
});
|
||||
|
||||
const isValidEnum = {
|
||||
name: 'isValidName',
|
||||
message:
|
||||
'${path} must match the following regex: /^[_A-Za-z][_0-9A-Za-z]*$/^',
|
||||
test: val => val === '' || ENUM_REGEX.test(val),
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
validators,
|
||||
|
||||
isValidName,
|
||||
isValidKey,
|
||||
isValidEnum,
|
||||
|
||||
VALID_TYPES,
|
||||
};
|
||||
|
@ -1,7 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
const yup = require('yup');
|
||||
const { validators, VALID_TYPES, isValidName } = require('./common');
|
||||
const {
|
||||
validators,
|
||||
VALID_TYPES,
|
||||
isValidName,
|
||||
isValidEnum,
|
||||
} = require('./common');
|
||||
|
||||
module.exports = obj => {
|
||||
return {
|
||||
@ -51,7 +56,7 @@ const getTypeShape = obj => {
|
||||
return {
|
||||
enum: yup
|
||||
.array()
|
||||
.of(yup.string().test(isValidName))
|
||||
.of(yup.string().test(isValidEnum))
|
||||
.min(1)
|
||||
.required(),
|
||||
default: yup
|
||||
|
Loading…
x
Reference in New Issue
Block a user