mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2973] [Issue]: Whole-word keyword matching silently fails for keywords starting/ending with a non-ASCII letter (accented names, CJK) #1549
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1549
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2973
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
When a lorebook entry has "Match whole words" enabled and its keyword starts or ends with a non-ASCII word character — accented Latin like "café", "José", "Zoë", "élan", or CJK like "北京" — the entry never activates, even when the keyword appears verbatim in the chat. World-info entries for non-English character and place names silently fail. The same keyword activates fine with whole-words off, and interior accents (e.g. "Müller") still match.
How to reproduce (try it yourself)
You'll see: the entry does not activate. (Directly:
testKeyword("café", "a café here", { matchWholeWords: true }) === false; same for "Zoë", "José", "北京", "élan".)Expected: the entry activates, as it does with "Match whole words" off, and as it does for interior accents like "Müller".
Where it is
packages/shared/src/utils/lorebook-keyword-matching.ts:49-56— thematchWholeWordsbranch oftestKeywordbuildsnew RegExp("\\b" + escaped + "\\b", flags).packages/server/src/services/lorebook/keyword-scanner.ts:511(testPrimaryKeys) and:518(testSecondaryKeys), withmatchOptionsbuilt at:503-508.What's happening
JavaScript's
\bboundary is defined only against the ASCII word class[A-Za-z0-9_]. Accented Latin, CJK, Cyrillic, etc. count as non-word characters. So when a keyword ends in such a character, the trailing\bsits between two non-word characters (e.g. "é" and a space) and never matches; same for a leading non-ASCII letter against the opening\b. Keywords with a non-ASCII char only in the interior still match because the boundaries fall on the ASCII first/last letters.Suggested fix
Stop relying on ASCII
\b. Build the pattern with the Unicode flag and lookaround boundaries against a Unicode letter/number class:This util also runs client-side (the in-editor keyword-test preview), so confirm the lookbehind target is acceptable — lookbehind and
\p{...}are supported in all current evergreen browsers and Node 18+. If support for very old browsers is required, an equivalent without lookbehind (capture the preceding char and assert it's a boundary, or test the match index against a Unicode boundary manually) achieves the same result. Add tests for café/José/Zoë/北京/élan withmatchWholeWordsenabled.AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Fixed in the v2.0.7 branch: whole-word lorebook keyword matching now uses Unicode-aware word-character boundaries and trims blank keywords before matching. Validated with pnpm check and pnpm regression:prompt.