Skip claude.ai/code and use word boundaries for mappings
Two user-reported conflicts when using the extension alongside Claude Code on the web and with short mappings: 1. Claude Code (claude.ai/code) sends real file paths, usernames, and shell commands to its tool runtime. Substituting any of these corrupts execution, forcing users to disable the extension for that app. early-hook.js and injector.js now short-circuit on that path so fetch/XHR are never wrapped and no page-world script is injected. 2. Explicit mappings used raw literal regexes, so "not" -> "bad" would rewrite "nothing" into "badhing". substitute/reveal/scan/diff (and their page-world mirrors) now add \b on word-character edges only, leaving non-word edges like "@foo" unchanged so they keep matching. https://claude.ai/code/session_01Y2YprLMx348eWD5C9Z4zpV
This commit is contained in:
@@ -345,6 +345,18 @@ test('Disabled mapping is skipped', () => {
|
||||
if (result.text.includes('Alex Demo')) throw 'Disabled mapping should not substitute';
|
||||
});
|
||||
|
||||
test('Mapping matches whole words only', () => {
|
||||
const result = SubstitutionEngine.substitute('nothing is not a thing, not even this', [
|
||||
{ real: 'not', substitute: 'bad', enabled: true }
|
||||
]);
|
||||
if (result.text.includes('bahing') || result.text.includes('badhing')) {
|
||||
throw `Should not match inside "nothing", got: ${result.text}`;
|
||||
}
|
||||
if (!/\bbad\b/.test(result.text)) {
|
||||
throw `Should still match standalone "not", got: ${result.text}`;
|
||||
}
|
||||
});
|
||||
|
||||
// ============================================================
|
||||
// SMART PATTERNS
|
||||
// ============================================================
|
||||
|
||||
Reference in New Issue
Block a user