bianbian coding life

便便代码人生: 关注技术, 翻译文档, 偶尔动动手

[原] 也许是prototype框架的bug

Posted by bianbian on 2008-03-08 08:03


本文Tags: , , , ,

不知道怎么给prototype提交bug report,就写在这里吧:
其实我没有测试过,只是看prototype源码的时候,觉得是个bug:
对String的原型(prototype)添加toJSON()函数只是转义了引号,未转义”\”:

  1. if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"';
  2. return "'" + escapedString.replace(/'/g, '\\\'') + "'";

如果用户在input里输入\\,转成string应该是”\\\\”,如果没有转义,再写回去的时候就丢了一个\
应该在转义引号前先转义\:

  1. .replace(/\\/g, '\\\\').replace(/"/g, '\\"')
标签: , , , ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in JavaScript, Technology | No Comments »