Activate your free membership today | Log-in

Thursday, April 19th, 2007

Fun Safari Bugs Episode 34

Category: Browsers, Safari, Tip

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.

Posted by Dion Almaer at 7:19 am

+++--
3.6 rating from 9 votes

8 Comments »

Comments feed TrackBack URI

That’s a really depressing bug which I’d never heard of before.

Comment by Dean Edwards — April 19, 2007

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

Comment by Andy Armstrong — April 19, 2007

As Andy noticed, using non-capturing parentheses does not solve the bug, e.g.:

/(?:.)+/.test(string)

will crash Safari too.

Comment by Tobie Langel — April 19, 2007

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.

Comment by Andy Armstrong — April 19, 2007

Good point Andy!

I’ve added a small test case from which you can generate the bug.

Comment by Tobie Langel — April 19, 2007

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.

Comment by Andy Armstrong — April 19, 2007

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.

Comment by Tobie Langel — April 19, 2007

How about fixing the mouse wheel issue in safari?

Comment by mousewheel — November 23, 2007

Leave a comment

You must be logged in to post a comment.