From 27012f54bb515bc252259022dd678e7de23138db Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 4 Aug 2022 20:09:41 +0800 Subject: [PATCH] :bug: fix https://github.com/Vanessa219/vditor/issues/1270 --- CHANGELOG.md | 2 ++ src/ts/sv/process.ts | 28 ++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d66aa4b80..e9756723b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -105,6 +105,8 @@ ### v3.8.16 / 2022-08 +* [1270](https://github.com/Vanessa219/vditor/issues/1270) 切换编辑模式 SV 脚注缩进丢失 `修复缺陷` +* [1274](https://github.com/Vanessa219/vditor/issues/1274) XSS 安全漏洞 `修复缺陷` * [1269](https://github.com/Vanessa219/vditor/issues/1269) 代码块自动补全会包含链接引用和脚注 `修复缺陷` * [1263](https://github.com/Vanessa219/vditor/issues/1263) 所见即所得和即使渲染只有空格输入时,不会触发 input 事件 `修复缺陷` * [1264](https://github.com/Vanessa219/vditor/issues/1264) 链接中,会强制将®解析为 ® 字符 `修复缺陷` diff --git a/src/ts/sv/process.ts b/src/ts/sv/process.ts index 5d6c33588..b58855969 100644 --- a/src/ts/sv/process.ts +++ b/src/ts/sv/process.ts @@ -16,13 +16,19 @@ export const processPaste = (vditor: IVditor, text: string) => { if (!blockElement) { blockElement = vditor.sv.element; } - const html = "
" + - vditor.lute.Md2VditorSVDOM(blockElement.textContent).replace(/
\n<\/span><\/span>
\n<\/span><\/span>
\n

\n
<') + - "
"; + let spinHTML = vditor.lute.SpinVditorSVDOM(blockElement.textContent) + if (spinHTML.indexOf('data-type="footnotes-link"') > -1 || + spinHTML.indexOf('data-type="link-ref-defs-block"') > -1) { + spinHTML = "
" + spinHTML + "
"; + } else { + spinHTML = "
" + + spinHTML.replace(/
\n<\/span><\/span>
\n<\/span><\/span>
\n

\n
<') + + "
"; + } if (blockElement.isEqualNode(vditor.sv.element)) { - blockElement.innerHTML = html; + blockElement.innerHTML = spinHTML; } else { - blockElement.outerHTML = html; + blockElement.outerHTML = spinHTML; } setRangeByWbr(vditor.sv.element, range); @@ -49,9 +55,15 @@ export const getSideByType = (spanNode: Node, type: string, isPrevious = true) = export const processSpinVditorSVDOM = (html: string, vditor: IVditor) => { log("SpinVditorSVDOM", html, "argument", vditor.options.debugger); - html = "
" + - vditor.lute.SpinVditorSVDOM(html).replace(/
\n<\/span><\/span>
\n<\/span><\/span>
\n

\n
<') + - "
"; + const spinHTML = vditor.lute.SpinVditorSVDOM(html) + if (spinHTML.indexOf('data-type="footnotes-link"') > -1 || + spinHTML.indexOf('data-type="link-ref-defs-block"') > -1) { + html = "
" + spinHTML + "
"; + } else { + html = "
" + + spinHTML.replace(/
\n<\/span><\/span>
\n<\/span><\/span>
\n

\n
<') + + "
"; + } log("SpinVditorSVDOM", html, "result", vditor.options.debugger); return html; };