Bug Tracker

Opened 10 years ago

Closed 9 years ago

#6152 closed enhancement (fixed)

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.

Change History (4)

comment:1 Changed 10 years ago by john

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).

comment:2 Changed 10 years ago by nikow

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.

comment:3 Changed 9 years ago by dmethvin

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.

comment:4 Changed 9 years ago by dmethvin

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.

Note: See TracTickets for help on using tickets.