From 45c9b77e82750cb6dbb9486ea71582c9e9a15251 Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 13 Jun 2025 14:42:25 +0800 Subject: [PATCH] fix: match var reg --- web/config/index.spec.ts | 26 ++++++++++++++++++++++++++ web/config/index.ts | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 web/config/index.spec.ts diff --git a/web/config/index.spec.ts b/web/config/index.spec.ts new file mode 100644 index 0000000000..06dfbdbf2f --- /dev/null +++ b/web/config/index.spec.ts @@ -0,0 +1,26 @@ +// 写测试用例, VAR_REGEX 能匹配的情况和不能匹配的情况 +import { VAR_REGEX, resetReg } from './index' +describe('VAR_REGEX', () => { + it('matched variable names', () => { + const vars = [ + // node output variables + '{{#1749783300519.text#}}', + '{{#1749783300519.llm.a#}}', + '{{#1749783300519.llm.a.b.c#}}', + '{{#1749783300519.llm.a#}}', + // system variables + '{{#sys.query#}}', + // conversation variables + '{{#conversation.aaa#}}', + // env variables + '{{#env.a#}}', + // rag variables + '{{#rag.1748945155129.a#}}', + '{{#rag.shared.bbb#}}', + ] + vars.forEach((variable) => { + expect(VAR_REGEX.test(variable)).toBe(true) + resetReg() + }) + }) +}) diff --git a/web/config/index.ts b/web/config/index.ts index f1fffc8646..5c49fe4061 100644 --- a/web/config/index.ts +++ b/web/config/index.ts @@ -275,7 +275,7 @@ Thought: {{agent_scratchpad}} `, } -export const VAR_REGEX = /\{\{(#[a-zA-Z0-9_-]{1,50}(\.[a-zA-Z_]?\w{0,29}){1,10}(\.[a-zA-Z0-9_-]{1,50})?#)\}\}/gi +export const VAR_REGEX = /\{\{(#[a-zA-Z0-9_-]{1,50}(\.\d+)?(\.[a-zA-Z_]\w{0,29}){1,10}#)\}\}/gi export const resetReg = () => VAR_REGEX.lastIndex = 0