- briksoftware Blog - https://briksoftware.com/blog -

NSCharacterSet bug in 10.5

I’ve just ran across a pretty unexpected bug in CuteClips. I was using NSCharacterSet to filter a String. This kept locking up some users computers. Turns out this is a bug in Mac OS X 10.5. Snow Leopard doesn’t show this bug so I guess it’s useless to report that to Apple.

The bug is pretty easy to reproduce:

NSMutableCharacterSet* characterSet = [NSMutableCharacterSet whitespaceAndNewlineCharacterSet];
[characterSet formUnionWithCharacterSet:[[NSCharacterSet alphanumericCharacterSet] invertedSet]];
NSString* longString = @””;
NSString* shortString = [longString stringByTrimmingCharactersInSet:characterSet];

The #stringByTrimmingCharactersInSet: Method will never return though. The easiest workaround is to check if the longString is empty, as the bug appears for empty strings.

@_karsten_