Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -2242,18 +2242,25 @@ - (OFArray *)componentsSeparatedByString: (OFString *)delimiter options: (int)options { void *pool; - OFMutableArray *array = [OFMutableArray array]; + OFMutableArray *array; const of_unichar_t *characters, *delimiterCharacters; bool skipEmpty = (options & OF_STRING_SKIP_EMPTY); size_t length = self.length; size_t delimiterLength = delimiter.length; size_t last; OFString *component; + if (delimiter == nil) + @throw [OFInvalidArgumentException exception]; + + if (delimiter.length == 0) + return [OFArray arrayWithObject: self]; + + array = [OFMutableArray array]; pool = objc_autoreleasePoolPush(); characters = self.characters; delimiterCharacters = delimiter.characters; Index: src/OFUTF8String.m ================================================================== --- src/OFUTF8String.m +++ src/OFUTF8String.m @@ -1111,18 +1111,26 @@ - (OFArray *)componentsSeparatedByString: (OFString *)delimiter options: (int)options { void *pool; OFMutableArray *array; - const char *cString = delimiter.UTF8String; - size_t cStringLength = delimiter.UTF8StringLength; + const char *cString; + size_t cStringLength; bool skipEmpty = (options & OF_STRING_SKIP_EMPTY); size_t last; OFString *component; + if (delimiter == nil) + @throw [OFInvalidArgumentException exception]; + + if (delimiter.length == 0) + return [OFArray arrayWithObject: self]; + array = [OFMutableArray array]; pool = objc_autoreleasePoolPush(); + cString = delimiter.UTF8String; + cStringLength = delimiter.UTF8StringLength; if (cStringLength > _s->cStringLength) { [array addObject: [[self copy] autorelease]]; objc_autoreleasePoolPop(pool); Index: tests/OFStringTests.m ================================================================== --- tests/OFStringTests.m +++ tests/OFStringTests.m @@ -603,11 +603,14 @@ [[a objectAtIndex: i++] isEqual: @"bar"] && [[a objectAtIndex: i++] isEqual: @""] && [[a objectAtIndex: i++] isEqual: @"baz"] && [[a objectAtIndex: i++] isEqual: @""] && [[a objectAtIndex: i++] isEqual: @""] && - a.count == i) + a.count == i && + (a = [C(@"foo") componentsSeparatedByString: @""]) && + [[a objectAtIndex: 0] isEqual: @"foo"] && + a.count == 1) i = 0; TEST(@"-[componentsSeparatedByString:options:]", (a = [C(@"fooXXbarXXXXbazXXXX") componentsSeparatedByString: @"XX"