Bug Tracker

Modify

Ticket #6152 (closed enhancement: fixed)

Opened 3 years ago

Last modified 3 years ago

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:
Blocking: Blocked by:

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

comment:1 Changed 3 years ago by john

  • Status changed from new to closed
  • Resolution set to wontfix

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 3 years ago by nikow

  • Status changed from closed to reopened
  • Resolution wontfix deleted

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 3 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 3 years ago by dmethvin

  • Priority set to undecided
  • Status changed from reopened to closed
  • Resolution set to fixed

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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.