Escape regex metacharacters in ASSISTANT_NAME for trigger pattern (#16)
ASSISTANT_NAME was interpolated directly into a regex without escaping. If the name contained regex metacharacters (e.g., @A.*), the trigger would match unintended patterns. This adds escapeRegex() to properly escape special characters before building the TRIGGER_PATTERN. https://claude.ai/code/session_01Lvuxq73qa9S4rtmGpX1WsP Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -19,7 +19,11 @@ export const CONTAINER_IMAGE = process.env.CONTAINER_IMAGE || 'nanoclaw-agent:la
|
|||||||
export const CONTAINER_TIMEOUT = parseInt(process.env.CONTAINER_TIMEOUT || '300000', 10);
|
export const CONTAINER_TIMEOUT = parseInt(process.env.CONTAINER_TIMEOUT || '300000', 10);
|
||||||
export const IPC_POLL_INTERVAL = 1000;
|
export const IPC_POLL_INTERVAL = 1000;
|
||||||
|
|
||||||
export const TRIGGER_PATTERN = new RegExp(`^@${ASSISTANT_NAME}\\b`, 'i');
|
function escapeRegex(str: string): string {
|
||||||
|
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||||
|
}
|
||||||
|
|
||||||
|
export const TRIGGER_PATTERN = new RegExp(`^@${escapeRegex(ASSISTANT_NAME)}\\b`, 'i');
|
||||||
|
|
||||||
// Timezone for scheduled tasks (cron expressions, etc.)
|
// Timezone for scheduled tasks (cron expressions, etc.)
|
||||||
// Uses system timezone by default
|
// Uses system timezone by default
|
||||||
|
|||||||
Reference in New Issue
Block a user