fix: 复查修复 5 处问题 — URL 双重转义/zen 泄漏/高亮环境不一致等
- parser: href/src/alt 改最小属性转义(escapeAttr 会把已实体化的 & 再转义成 &amp;,导致链接 URL 双重转义错误);新增 URL/alt 防回归测试 - core: _pushHistory 增加 maxLength 兜底截断(exec/Tab/Smart Enter/括号 自动闭合等程序化路径此前绕过 maxlength 限制) - core: destroy 时清理 Zen 模式的 document mousemove 监听(此前泄漏) - highlight: 自写环境无关转义(仅 & < >),修复 Node 环境下字符串高亮 失效、浏览器与 SSR 输出不一致的问题 - floating-toolbar/context-menu: toggleFloatingToolbar/registerContextMenu 恢复链式 return this(拆分时丢失) - plugins: 补齐 3 个硬编码文案的 i18n(regex/shortcuts/imageTooLarge), 6 种语言同步 - 测试 768 → 780
This commit is contained in:
@@ -1328,3 +1328,29 @@ describe('parseMarkdown - v0.2.5 title 转义', () => {
|
||||
expect(html).toContain('title="say "hi""');
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseMarkdown - v0.2.5 URL 属性无双重转义', () => {
|
||||
test('链接 URL 中的 & 不双重转义', () => {
|
||||
const html = parseMarkdown('[x](https://example.com/?a=1&b=2)');
|
||||
expect(html).toContain('href="https://example.com/?a=1&b=2"');
|
||||
expect(html).not.toContain('&amp;');
|
||||
});
|
||||
|
||||
test('图片 alt 中的 & 不双重转义', () => {
|
||||
const html = parseMarkdown('');
|
||||
expect(html).toContain('alt="a & b"');
|
||||
expect(html).not.toContain('&amp;');
|
||||
});
|
||||
|
||||
test('引用链接 URL 中的 & 不被破坏', () => {
|
||||
const html = parseMarkdown('[r]: https://example.com/?a=1&b=2\n\n[x][r]');
|
||||
expect(html).toContain('href="https://example.com/?a=1&b=2"');
|
||||
expect(html).not.toContain('&amp;');
|
||||
});
|
||||
|
||||
test('URL 中的引号仍被转义防注入', () => {
|
||||
const html = parseMarkdown('[x](https://example.com/"onclick="alert(1))');
|
||||
expect(html).not.toContain(' onclick="');
|
||||
expect(html).toContain('"onclick');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user