diff --git a/back/api/env.ts b/back/api/env.ts index f542339d..a54aea1c 100644 --- a/back/api/env.ts +++ b/back/api/env.ts @@ -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(''), }), ), diff --git a/back/services/env.ts b/back/services/env.ts index 266afe90..b43d6f03 100644 --- a/back/services/env.ts +++ b/back/services/env.ts @@ -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, '\\\\')