Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (codex): Unicode-aware word boundaries for canon name matching

[._.]/ Adam Eivya87c43cbd54d
diff --git a/client/src/lib/editorialChecks.js b/client/src/lib/editorialChecks.js
index 5ab21d9e67..680c63f814 100644
--- a/client/src/lib/editorialChecks.js
+++ b/client/src/lib/editorialChecks.js
@@ -421,7 +421,11 @@ function buildCanonMatcher(entities = []) {
alts.push(escapeRegExp(e.name));
}
if (!alts.length) return null;
- return { byName, re: new RegExp(`\\b(${alts.join('|')})\\b`, 'gi') };
+ // Unicode-aware boundaries: JS `\b` is ASCII-only, so accented/non-Latin names
+ // (Élodie, Søren, 李雷) would never match in finding text. Lookarounds that treat
+ // any Unicode letter/number as a "word" char anchor the match on real word
+ // edges across scripts. The `u` flag is required for the \p{…} classes.
+ return { byName, re: new RegExp(`(?<![\\p{L}\\p{N}])(${alts.join('|')})(?![\\p{L}\\p{N}])`, 'giu') };
}
/**
diff --git a/client/src/lib/editorialChecks.test.js b/client/src/lib/editorialChecks.test.js
index df2be56c7f..a4161eb340 100644
--- a/client/src/lib/editorialChecks.test.js
+++ b/client/src/lib/editorialChecks.test.js
@@ -400,6 +400,14 @@ describe('canon entity references in findings (#1631)', () => {
expect(refs.map((e) => e.name)).toEqual(['Aria', 'Jon', 'The Atrium']);
});
+ it('matches accented / non-ASCII names (Unicode-aware boundaries, not ASCII \\b)', () => {
+ const entities = canonEntitiesFromUniverse({ characters: [{ id: 'e1', name: 'Élodie' }, { id: 'e2', name: 'Søren' }] });
+ const refs = canonReferencesInText('Élodie argues with Søren at dawn', entities);
+ expect(refs.map((e) => e.name)).toEqual(['Élodie', 'Søren']);
+ // Still whole-word: a name embedded in a longer accented word does not match.
+ expect(canonReferencesInText('Élodies', entities)).toEqual([]);
+ });
+
it('handles empty/no-entity inputs without throwing', () => {
expect(linkifyCanonEntities('', [])).toEqual([]);
expect(linkifyCanonEntities('plain text', [])).toEqual([{ text: 'plain text' }]);