ivarptr / yu-writer.site

A feature-rich, efficient text editor - Web Site
Apache License 2.0
1.2k stars 77 forks source link

在文中插入糟糕的正则表达式会引发页面卡死 #558

Open SukkaW opened 5 years ago

SukkaW commented 5 years ago

Platform/操作系统类型 macOS? Windows? or Linux?

Windows

OS version/操作系统版本 macOS 10.13, 10.14, ... Windows 10 1709, 1803, ... Ubuntu 16.04, 18.04 ...

Windows 10 1903

Application version/应用程序的版本号 x.y.z

0.5.3

Describe the bug/错误描述 A clear and concise description of what the bug is.

RT

To Reproduce/如何重现该错误 (如果错误描述能说明清楚则忽略并删除该小节) Steps to reproduce the behavior:

在文中直接插入如下的正则表达式(不使用代码块符号包裹):

(?:(?:\"|'|\]|\}|\\|\d|(?:nan|infinity|true|false|null|undefined|symbol|math)|\`|\-|\+)+[)]*;?((?:\s|-|~|!|{}|\|\||\+)*.*(?:.*=.*)))

这会引起严重的卡顿(操作延迟);当我终于设法用代码块将这段正则表达式包裹起来以后,卡顿基本消失。

我正在 Yu Writer 上翻译 Cloudflare 博客中 https://blog.cloudflare.com/details-of-the-cloudflare-outage-on-july-2-2019/ 一文。讽刺的是,这条正则表达式导致 Cloudflare 全球性宕机,甚至险些也引发了 Yu Writer 的崩溃。

hemashushu commented 5 years ago

@SukkaW 哈哈,是的,我准备在接近正式版时重写一遍编辑框的语法加亮算法,目前用的方法效率很低,特别当正文有大量符号之类的文本时,这个算法甚至会陷入死循环😂,感谢反馈!