Chr*_*ard -6 javascript regex firefox parsing google-chrome
我有JavaScript代码,如:
quotes = [];
quotes[quotes.length] = "ABC quote";
quotes[quotes.length] = "DEF quote";
...
Run Code Online (Sandbox Code Playgroud)
其中一条线特别是:
quotes[quotes.length] = "Mark Twain said, 'The secret source of humor itself is not joy but sorrow. There is no humor in Heaven.'<br /><a href=\"/pain\/">Humor Delivers Pain</a>";
Run Code Online (Sandbox Code Playgroud)
Chrome正在抱怨这一行,超过一百行,我试图解决撇号被'替换.然而,它仍然抱怨这一行,语法高亮显然没有看到开头的双引号,只有正则表达式,/ pain /"> Humor Delivers Pain </.
表达式之前的所有内容都按照预期的方式突出显示为字符串,即使这样的正则表达式字符串是样板子字符串; 上一行,就像之前的行一样:
quotes[quotes.length] = "The author was shaped by M.K. Gandhi. Here is why he is taking leave of Gandhi.<br /><a href=\"/gandhi/\">Farewell to Gandhi</a>";
Run Code Online (Sandbox Code Playgroud)
即使这包含引号内的正则表达式文字,它也会被解释为预期的,作为包含转义引号的双引号字符串.
我正在尝试这个的页面是http://JonathansCorner.com/firestorm/.它旨在打印页面顶部的通知,并更改链接.现在它正在撞上马克吐温的名言.
Firefox引发了对Twain引用的抱怨,称在声明之前有一个缺少的分号.我不知道那是从哪里来的; 这可能是报价较高的二次损害吗?
JavaScript本身位于http://jonathanscorner.com/include/deprecation_notice.js.
- 编辑 -
@Lightness,问题表现在前一行的两行样本,然后是绘制错误的行.有一个相同的错误,前面的脚本行显示在:
quotes = [];
quotes[quotes.length] = "The author was shaped by M.K. Gandhi. Here is why he is taking leave of Gandhi.<br /><a href=\"/gandhi/\">Farewell to Gandhi</a>";
quotes[quotes.length] = "Mark Twain said, 'The secret source of humor itself is not joy but sorrow. There is no humor in Heaven.'<br /><a href=\"/pain\/">Humor Delivers Pain</a>";
Run Code Online (Sandbox Code Playgroud)
<a href=\"/pain\/">
Run Code Online (Sandbox Code Playgroud)
第二个双引号未被转义.\"没有/".
将这些引号存储在纯文本文件或数据库中可能更可靠,并自动转义它们.手工逃避大量文本是件苦差事.