Skip to content
This repository was archived by the owner on May 19, 2022. It is now read-only.

markdown 编辑器在预览时, 右边的内容在特定的情况下展示不正确 #250

Open
xqin opened this issue Dec 29, 2015 · 2 comments
Assignees

Comments

@xqin
Copy link

xqin commented Dec 29, 2015

重现的POC(复制下面的内容至sf的 markdown 编辑器区域内):
$'

image

为什么会发现这个问题呢, 要从今天回答的一个问题说起:
帖子地址为: http://segmentfault.com/q/1010000004217885
在编辑器里输入 mysql 语句的时候, 里面有正则表达式, 然后就看到右边的预览区域出现了很神奇的东东.
image

最后经过精简, 得到了上面那样的内容.

@xqin
Copy link
Author

xqin commented Dec 29, 2015

根据 markdown 的源代码, 现分析如下:
$' 在做为 replace 方法的第二个参数之前, 有一个 htmlspecialchars 的方法, 会把 ' 转换为 ',
然后就得到了 $' 这样一个字符串, 然后这个字符串中的 $&replace 方法中有特殊含义, 可参考 Specifying a string as a parameter, 然后就产生了神奇的效果了.

var text = "|\r4f346db62b94a3d24e27c235be4c69420\r|";

text = text.replace('|\r4f346db62b94a3d24e27c235be4c69420\r|', "<code>$&#039;</code>");

console.log(JSON.stringify(text));

text = text.replace('|\r4f346db62b94a3d24e27c235be4c69420\r|', "<code>$&#039;</code>");

console.log(JSON.stringify(text));

/*结果如下:
"<code>|\r4f346db62b94a3d24e27c235be4c69420\r|#039;</code>"
"<code><code>|\r4f346db62b94a3d24e27c235be4c69420\r|#039;</code>#039;</code>"
*/

然后就永远替换不完了.

再然后 releaseHolder 方法中有一个 deep 的变量,用于防止这种死循环, 所以会看到出现 10 次同样的内容.
image

@Integ
Copy link

Integ commented Jan 6, 2016

谢谢反馈,正在处理中

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants