修复环境变量名称验证

This commit is contained in:
whyour 2022-10-16 09:22:37 +08:00
parent ff44330aa1
commit d44a8966f2
2 changed files with 5 additions and 4 deletions

View File

@ -39,7 +39,9 @@ export default (app: Router) => {
body: Joi.array().items(
Joi.object({
value: Joi.string().required(),
name: Joi.string().required(),
name: Joi.string()
.required()
.pattern(/^[a-zA-Z_][0-9a-zA-Z_]*$/),
remarks: Joi.string().optional().allow(''),
}),
),

View File

@ -158,7 +158,7 @@ export default class EnvService {
const envs = await this.envs(
'',
{ position: -1 },
{ name: { [Op.not]: null } },
{ name: { [Op.not]: null }, status: EnvStatus.normal },
);
const groups = _.groupBy(envs, 'name');
let env_string = '';
@ -167,9 +167,8 @@ export default class EnvService {
const group = groups[key];
// 忽略不符合bash要求的环境变量名称
if (/^[a-zA-Z_][0-9a-zA-Z_]+$/.test(key)) {
if (/^[a-zA-Z_][0-9a-zA-Z_]*$/.test(key)) {
let value = _(group)
.filter((x) => x.status !== EnvStatus.disabled)
.map('value')
.join('&')
.replace(/(\\)[^n]/g, '\\\\')