From 8a308f45f06d5f2808428f674bbe8a7e3a44beeb Mon Sep 17 00:00:00 2001 From: Aleksander Grygier Date: Tue, 29 Sep 2026 13:40:43 +0200 Subject: [PATCH] ui : escape sidecar tokens in the regex alternation Assisted-by: pi:zai-org/GLM-5.3-Flash --- tools/ui/src/lib/constants/model-id.constants.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/ui/src/lib/constants/model-id.constants.ts b/tools/ui/src/lib/constants/model-id.constants.ts index 53d361122d..d4ffc8b0ff 100644 --- a/tools/ui/src/lib/constants/model-id.constants.ts +++ b/tools/ui/src/lib/constants/model-id.constants.ts @@ -15,7 +15,15 @@ export const SIDECAR_TOKENS: string[] = [ /** Separator between token alternatives in the sidecar regexes. */ const REGEX_ALTERNATION_SEPARATOR = '|'; -const SIDECAR_TOKEN_ALTERNATION = SIDECAR_TOKENS.join(REGEX_ALTERNATION_SEPARATOR); + +/** Escape regex metacharacters so a token change cannot silently corrupt the alternation. */ +function escapeRegExp(token: string): string { + return token.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); +} + +const SIDECAR_TOKEN_ALTERNATION = SIDECAR_TOKENS.map(escapeRegExp).join( + REGEX_ALTERNATION_SEPARATOR +); export const MODEL_ID = { /**