cccc_code_exec import guard false-positives on strings/comments
Summary
cccc_code_exec rejects source when JavaScript string/comment contents merely contain text that looks like import or require.
The current guard scans the raw source with regexes, so non-executable text can trigger unsupported_js.
Tested on CCCC v0.4.40.
Reproduction
This should be valid because the Python text is only a JavaScript string:
const python = "from pathlib import Path";
text(python);
Actual result:
unsupported_js: cccc_code_exec does not support import
Similar false positives occur in comments and template raw text, for example:
// import fs from 'node:fs'
text("ok");
By contrast, real imports should remain blocked:
await import('node:fs');
Expected
- Import-like text inside string literals/comments/template raw text is allowed.
- Real static/dynamic imports and
require()remain rejected.
Cause
crates/cccc-mcp/src/code_mode.rs applies the import/require regexes to the full raw source rather than executable-code regions.
Local verification
A local fix that masks JS strings/comments/template raw sections before applying the existing guard was tested successfully:
- string containing
from pathlib import Path: allowed - line/block comment containing import/require syntax: allowed
- template raw text containing import syntax: allowed
- real
import()and staticimport: still rejected cccc-mcpunit tests: 73 passed, 0 failed
Thanks for the clear reproduction! Confirmed and fixed in the pending patch: import-like text in strings, comments and templates is accepted, while actual Node module loading remains unavailable. Added regression coverage, including executable template expressions.