From ec2b167f92afe53b4aed11e490d7906786e77a19 Mon Sep 17 00:00:00 2001 From: bielie Date: Wed, 25 Feb 2026 23:46:56 +0800 Subject: [PATCH] fix(ena-planner): harden url/think cleanup and remove hardcoded vars --- modules/ena-planner/ena-planner.js | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/modules/ena-planner/ena-planner.js b/modules/ena-planner/ena-planner.js index a28f2cc..565829d 100644 --- a/modules/ena-planner/ena-planner.js +++ b/modules/ena-planner/ena-planner.js @@ -226,7 +226,10 @@ function buildUrl(path) { const p = prefix.startsWith('/') ? prefix : `/${prefix}`; const finalPrefix = p.replace(/\/+$/g, ''); const finalPath = path.startsWith('/') ? path : `/${path}`; - return `${base}${finalPrefix}${finalPath}`; + const escapedPrefix = finalPrefix.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + const hasSameSuffix = !!finalPrefix && new RegExp(`${escapedPrefix}$`, 'i').test(base); + const normalizedBase = hasSameSuffix ? base.slice(0, -finalPrefix.length) : base; + return `${normalizedBase}${finalPrefix}${finalPath}`; } function setSendUIBusy(busy) { @@ -304,15 +307,11 @@ function formatCharCardBlock(charObj) { function cleanAiMessageText(text) { let out = String(text ?? ''); - // 1) Strip everything before and including (handles unclosed think blocks) - // Pattern: content without opening followed by - out = out.replace(/^[\s\S]*?<\/think>/i, ''); - - // 2) Also strip properly wrapped ... blocks + // 1) Strip properly wrapped / blocks only. out = out.replace(/]*>[\s\S]*?<\/think>/gi, ''); out = out.replace(/]*>[\s\S]*?<\/thinking>/gi, ''); - // 3) Strip user-configured exclude tags + // 2) Strip user-configured exclude tags // NOTE: JS \b does NOT work after CJK characters, so we use [^>]*> instead. // Order matters: try block match first (greedy), then mop up orphan open/close tags. const s = ensureSettings(); @@ -734,17 +733,8 @@ function buildEjsContext() { return value; } - // Compute common derived values that entries might reference - const fire = Number(getvar('stat_data.蒂娜.火')) || 0; - const ice = Number(getvar('stat_data.蒂娜.冰')) || 0; - const dark = Number(getvar('stat_data.蒂娜.暗')) || 0; - const light = Number(getvar('stat_data.蒂娜.光')) || 0; - const maxAttrValue = Math.max(fire, ice, dark, light); - return { getvar, setvar, - fire, ice, dark, light, - maxAttrValue, Number, Math, JSON, String, Array, Object, parseInt, parseFloat, console: { log: () => { }, warn: () => { }, error: () => { } }, };