JSON parser not accepting some responses #107

Open
pyjsorg opened this Issue Apr 27, 2012 · 1 comment

Comments

Projects
None yet
1 participant
Contributor

pyjsorg commented Apr 27, 2012

On our (web2py) server application, certain valid JSON responses are not being accepted by the current JSON parser. The cause seems to be the current regex validation clause which does not exactly match the one recommended by RFC 4627 (the JSON RFC):

Current code:

return (/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(@{{str}})) &&
         eval('(' + @{{str}} + ')');           

RFC 4627 compatible code:

return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(@{{str}}.replace(/"(\\.|[^"\\])*"/g, ''))) &&
         eval('(' + @{{str}} + ')');

With the current code, an exception is thrown on some valid responses. Handling this exception produces an "Empty Response" result (also not correct, but that's another bug).

The proposed change is attached in a diff

Original issue: http://code.google.com/p/pyjamas/issues/detail?id=616 (May 16, 2011 10:54:48)

Contributor

pyjsorg commented Apr 27, 2012

From rich.new...@gmail.com on May 16, 2011 10:57:57:
This change was pushed in commit db67462

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment