From d44a8966f256f319ed582aa5e504ba6ebe251a17 Mon Sep 17 00:00:00 2001 From: whyour Date: Sun, 16 Oct 2022 09:22:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E5=90=8D=E7=A7=B0=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/api/env.ts | 4 +++- back/services/env.ts | 5 ++--- 2 files changed, 5 insertions(+), 4 deletions(-) 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, '\\\\')