RESOLVED INVALID 46057
Bad end-of-line management in JSON.parse
https://bugs.webkit.org/show_bug.cgi?id=46057
Summary Bad end-of-line management in JSON.parse
Guilaume Ayoub
Reported 2010-09-19 11:55:08 PDT
Using the '\n' string (not the EOL character, the string with '\' and 'n') in JSON.parse gives an error. The error happens both in the javascript console and when parsing a sting outside the console. Example: 1. Open the javascript console 2. Type: JSON.parse('["\n"]') This should create a list containing a string with the EOL character, but it gives an error. The bug appears with Epiphany (Linux) and Safari (Windows). No bug with Firefox or Chrome.
Attachments
Oliver Hunt
Comment 1 2010-09-20 11:58:34 PDT
Firefox and Chrome are both incorrect -- When you do JSON.parse('"\n"') you are asking for the JSON parser to accept a new line in the middle of a string literal. Because you have not escaped the new line character in the string that you pass to JSON, you have only escaped it in the JS parser. The string passed to JSON.parse must include the escapes so you actually need to do JSON.parse('"\\n"') The \\ escapes the \ when the script is parse, so you are then passing the string "\n" to the JSON parser.
Oliver Hunt
Comment 2 2010-09-20 12:07:25 PDT
And it's fixed in firefox 4, and i've filed http://code.google.com/p/v8/issues/detail?id=870
Guilaume Ayoub
Comment 3 2010-09-20 12:20:07 PDT
Thank you for your very clear explanation, I'm sorry for the noise.
Note You need to log in before you can comment on or make changes to this bug.