Skip to main content

Bug Tracker

Side navigation

#6152 closed enhancement (fixed)

Opened February 23, 2010 02:40PM UTC

Closed September 27, 2010 03:21AM UTC

parseJSON regex is redundant when native parsing is available.

Reported by: nikow Owned by:
Priority: undecided Milestone: 1.4.2
Component: misc Version: 1.4.1
Keywords: JSON Cc:
Blocked by: Blocking:
Description

In the parseJSON (line 496) a regex cleanup is performed before the string is parsed. If the browser supports native JSON parsing then this is redundant, since the browser is responsible for filtering the JSON string.

For very large JSON objects this is a real problem, since the regex can cause an Error in Firefox (3.0 to 3.6 raise 'script stack space quota is exhausted'). This can happen in cases where the naive eval approach of jQuery 1.3 did not cause such problems and was fast enough for these large objects to be usable.

Therefore the regex checking should only be done if no native parser is found.

Attachments (0)
Change History (4)

Changed February 23, 2010 04:26PM UTC by john comment:1

resolution: → wontfix
status: newclosed

Actually, not true - for example Chrome has problems with their parsing and detection so we have to work around it - additionally it creates a consistent set of error messages across all browsers (again, not the case).

Changed February 23, 2010 06:03PM UTC by nikow comment:2

resolution: wontfix
status: closedreopened

You could work around that by first trying to use the native JSON on the raw string, and only in the case of failure perform the sanitizing. Then Chrome users could still benefit from the low overhead as long as the JSON is not problematic (which should be most of the time).

Duplicating the browser work by default still seems strange to me, though I don't know how large the performance impact is in the average case (in my case it was fatal).

Taking the argument to the extreme would imply that jQuery should implement its own HTML rendering engine just to guarantee "consistent" rendering across all browsers.

Please reclose it if you still disagree, I won't open it again, sorry for the trouble.

Changed August 10, 2010 12:16AM UTC by dmethvin comment:3

As John says, at the moment there are browsers that accept invalid JSON, to the point of allowing nearly arbitrary Javascript to be executed.

http://code.google.com/p/v8/issues/detail?id=372

Eventually I would like to see us be able to do this optimization. Perhaps we can wait a year for the rat to get through the snake.

Changed September 27, 2010 03:21AM UTC by dmethvin comment:4

priority: → undecided
resolution: → fixed
status: reopenedclosed

The regexp problem caused by large JSON objects should have been fixed by the recent optimizations in this commit:

http://github.com/jquery/jquery/commit/9dc6e0c572b9c809a3a4c123071d96d48a01dd1c#L2R40

That was the bug; the regexp check is not (yet at least) redundant since some native JSON implementations accept invalid JSON strings.