Thursday, April 19th, 2007
Fun Safari Bugs Episode 34
Tobie Langel fearlessly deals with browser quirks so Prototype users will not have too.
His latest battle revolves around a Regex bug that causes Safari to crash when the string is large.
/(.)+/.test(string);
They fixed the usage of this in some areas but still have issues with JSON sanitization.
The good news is that WebKit nightly seems happy. Come on Leopard! It makes you wish that the browser vendors could try {} catch {} around these issues so you don’t get crashes.












That’s a really depressing bug which I’d never heard of before.
I’ve posted a possible fix in the comments on Tobie’s site. I’ll link it here too in case anyone else is having the same problem.
Here’s my response to Tobie’s post:
http://www.hexten.net/wiki/index.php/Safari_JS_bug
As Andy noticed, using non-capturing parentheses does not solve the bug, e.g.:
/(?:.)+/.test(string)will crash Safari too.
Yeah, the key is to modify the fragment that matches the interior of strings so it consumes as many characters as possible - that fixes the problem in the sense that the RE engine has to do /much/ less backtracking.
Good point Andy!
I’ve added a small test case from which you can generate the bug.
Note: the capturing parens thing is a complete red herring. My /first/ assumption was that that’d fix it - but as you know it doesn’t.
So the /only fix/ you need is the modification to make the string interior pattern consume as many characters as possible.
I’ve posted a follow-up to this issue more directly targeted at improving the JSON parsing, thanks to Andy’s suggestions. Again, any improvements are welcomed.
How about fixing the mouse wheel issue in safari?