Bug Tracker

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#10336 closed bug (invalid)

parseJSON validation is inaccurate

Reported by: anonymous Owned by:
Priority: low Milestone: None
Component: core Version: 1.6.4
Keywords: Cc:
Blocked by: Blocking:


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:


JQuery 1.4.1+ affected on all platforms

Change History (5)

comment:1 Changed 10 years ago by Rick Waldron

Component: unfiledcore
Priority: undecidedlow
Resolution: invalid
Status: newclosed

comment:2 Changed 10 years ago by anonymous

The behavior is inconsistent, though, because the method of validation is bogus.


comment:3 Changed 10 years ago by Rick Waldron

Sorry, but that "json" string is the only bogus thing here...


comment:4 Changed 10 years ago by anonymous

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.

comment:5 Changed 10 years ago by Rick Waldron

They both produce an "unexpected token" syntax error when using native JSON.parse()

Why is it so hard to create _valid_ JSON?

Last edited 10 years ago by Rick Waldron (previous) (diff)
Note: See TracTickets for help on using tickets.