1.3 KiB
1.3 KiB
escapeHtml parity test (OPT-6 收编验证)
utils.js:38 是 blog-app 唯一一份 escapeHtml 实现.
ai-panel.js 已通过 import { escapeHtml } from './utils.js' (line 9) 复用.
无任何本地副本, 无 div.textContent-based 实现.
字符集
utils.js:38 escape 5 个字符: & < > " '
&→&<→<>→>"→"'→'(注: 任务 spec 写的是', 但 utils.js 用十进制', 语义等价 — 都是单引号的 HTML entity)
测试用例 (行为对齐)
| 输入 | 期望输出 | utils.js 输出 | 一致? |
|---|---|---|---|
<script>alert(1)</script> |
<script>alert(1)</script> |
同 | ✓ |
a & b |
a & b |
同 | ✓ |
"quote" |
"quote" |
同 | ✓ |
'apos' |
'apos' |
同 (等价于 ') |
✓ |
<img onerror="x"> |
<img onerror="x"> |
同 | ✓ |
验证命令
grep -nE "function escapeHtml|const escapeHtml" static/js/ai-panel.js
# 预期: 无输出 (本地实现已不存在)
grep -nE "^import.*escapeHtml" static/js/ai-panel.js
# 预期: 9:import { escapeHtml } from './utils.js';
grep -rnE "function escapeHtml|const escapeHtml" static/js/
# 预期: 仅 utils.js:38 一处
状态
OPT-6 收编完成 — ai-panel.js 第三份本地实现已不存在.