Side navigation
#10336 closed bug (invalid)
Opened September 23, 2011 07:03PM UTC
Closed September 23, 2011 07:13PM UTC
Last modified September 26, 2011 12:59AM UTC
parseJSON validation is inaccurate
Reported by: | anonymous | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | core | Version: | 1.6.4 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
The current method for validating JSON for parsing is inaccurate and buggy. For example, jQuery.parseJSON("{,}") passes the existing test, and results in a syntax error when trying to eval it, where jquery should handle the error.
This patch introduces an alternative validation method that really ensures that the input is valid JSON before evaluating it:
https://github.com/jquery/jquery/pull/516
JQuery 1.4.1+ affected on all platforms
Attachments (0)
Change History (5)
Changed September 23, 2011 07:13PM UTC by comment:1
component: | unfiled → core |
---|---|
priority: | undecided → low |
resolution: | → invalid |
status: | new → closed |
Changed September 23, 2011 07:18PM UTC by comment:2
The behavior is inconsistent, though, because the method of validation is bogus.
Changed September 23, 2011 07:35PM UTC by comment:3
Sorry, but that "json" string is the only bogus thing here...
Changed September 26, 2011 12:54AM UTC by comment:4
But why is it okay that {"a":5,} produces a different exception than {'a':5,}? It means that code handling the resulting exceptions has to handle two cases for the same error.
Changed September 26, 2011 12:59AM UTC by comment:5
_comment0: | They both produce an "unexpected token" syntax error when using native JSON.parse() → 1316998781987001 |
---|
They both produce an "unexpected token" syntax error when using native JSON.parse()
Why is it so hard to create _valid_ JSON?
That error is exactly correct, "{,}" is not valid
http://gyazo.com/88815ad637cc0fccc9ee58751c45d0f9.png
http://gyazo.com/fe06c62923b84b8b5a5aa8939fd43fb9.png
jsonlint...
http://gyazo.com/a604c8ccff158be76b83288b337d2a0c.png