一键导入
template-literal-js-escaping
Debug silent JS failures from template literal backslash escaping when embedding JS strings in server-rendered HTML
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Debug silent JS failures from template literal backslash escaping when embedding JS strings in server-rendered HTML
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
Expert instructions to implement and verify ML-DSA-65 post-quantum cryptographic signatures and agentic workflow security.
Post-quantum cryptography secrets management system for protecting API keys, tokens, and private data. Includes the 10 browser_secrets_* MCP tools (betterbrowsermcp v0.7.0+ rotates v0.8.0+), the append-only audit log at ~/.config/pqc-secrets/audit.log, and the PQC Rust binary (ML-KEM-768 + AES-256-GCM).
Diagnose missing files in git worktrees — when a file exists in the main worktree but not in a linked worktree, check .gitignore
Integrate ML-KEM-768 + AES-256-GCM key persistence into a Node.js server via a Python UV inline script
基于 SOC 职业分类
| name | template-literal-js-escaping |
| description | Debug silent JS failures from template literal backslash escaping when embedding JS strings in server-rendered HTML |
| source | auto-skill |
| extracted_at | 2026-05-30T01:22:57.937Z |
When a TypeScript server renders inline JavaScript inside a backtick template literal (res.send(\...`)), single-quote escape sequences behave counterintuitively — 'produces just', not '`. This can silently break entire script blocks.
<script> block silently failsfetch() calls never complete — every section shows "Loading..."onclick handlers do nothingIn a JavaScript template literal (backtick-delimited), \' is an unnecessary escape — the backslash is consumed and the output is just '. To produce a literal backslash in the output, you need \\.
| Source (in template literal) | Rendered output | What you probably wanted |
|---|---|---|
\' | ' | \' (for escaped JS string quote) |
\\' | \' | ✅ correct |
\\\' | \\' | double backslash + quote |
"\\'" | "\'" | double-quoted string with escaped quote |
Concrete example of the bug:
// Source (inside backtick template literal):
', \'' + escapeHtml(m) + '\')">' +
// Rendered JavaScript (what the browser receives):
', '' + escapeHtml(m) + '')">' +
// ^^ two adjacent string literals with no + operator → SyntaxError
The rendered ', '' is parsed as: string , ends at first ', then ' starts a new empty string — but there's no + between them. JavaScript forbids adjacent string literals without an operator.
<script> blocknode --check --input-type=module:
curl -s http://localhost:PORT/config \
| sed -n '/<script>/,/<\/script>/p' \
| sed '1s/<script>//; $s/<\/script>//' \
| node --check --input-type=module
node --check <<'JS' ... JSReplace \' with \\' in all template-literals that need to produce an escaped single quote in the generated JavaScript:
// Before (broken):
', \'' + escapeHtml(m) + '\')">' +
', \'codingScore\', this.value)"></div>' +
'\'' + escapeHtml(id) + '\', \'up\')"'
// After (fixed):
', \\'' + escapeHtml(m) + '\\')">' +
', \\'codingScore\\', this.value)"></div>' +
'\\'' + escapeHtml(id) + '\\', \\'up\\')"'
Search the codebase for \' inside template literals used for HTML generation:
grep -n "\\\\'" src/index.ts | grep -v "^[0-9]*:.*//"
Every \' in a template-literal that should survive into the rendered JS output must become \\'. The only safe \' in a template literal is when you actually want a plain ' character in the output (e.g., inside an HTML attribute value that doesn't need JS escaping).
tsc) reports no errors — the template literal is syntactically valid', '' + vs ', \'' + differ by one characterconsole.error runsnode --check on extracted <script> blocks from key pagesJSON.stringify() over manual string escaping for embedding data values in generated JS