Sanitize JSON regexp bug

written by Tobie on April 19th, 2007 @ 04:52 PM

Following my last post on a critical Safari's regexp bug (it actually crashes the browser), Andy Armstrong suggested a partial solution to the problem:

Here's a tentative fix to JSON's sanitize regexp based on it:

/^("(\.|[^"\\n\r]*)*?"|[,:{}[]0-9.\-+Eaeflnr-u \n\r\t]*)+?$/

instead of the original:

/^("(\.|[^"\\n\r])*?"|[,:{}[]0-9.\-+Eaeflnr-u \n\r\t])+?$/

Although it does not entirely solve the problem, it does allow longer strings to be parsed without crashing Safari.

Again, your mileage may vary depending on your machine.

Here's a test-case for it.

Any improvements, suggestions, etc. are warmly welcomed.

Comments

Comments are closed