* Source/GSAttributedString.m: Throw an exception if the string object

passed to -initWithString:attributes: doesn't respond to -length, or if
it is nil. This is the same behaviour as OS X.
* Source/NSAttributedString.m (-init): Call -initWithString:attributes:
with @"" instead of nil, since passing nil now causes an exception
to be thrown.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@33595 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
ericwa 2011-07-21 01:23:08 +00:00
parent 9623471068
commit 5800130467
3 changed files with 32 additions and 1 deletions

View file

@ -461,6 +461,17 @@ _attributesAtIndexEffectiveRange(
{
NSZone *z = [self zone];
if (nil == aString)
{
[NSException raise: NSInvalidArgumentException
format: @"aString object passed to -[GSAttributedString initWithString:attributes:] is nil"];
}
if (![aString respondsToSelector: @selector(length)])
{
[NSException raise: NSInvalidArgumentException
format: @"aString object passed to -[GSAttributedString initWithString:attributes:] does not respond to -length"];
}
_infoArray = [[NSMutableArray allocWithZone: z] initWithCapacity: 1];
if (aString != nil && [aString isKindOfClass: [NSAttributedString class]])
{
@ -562,6 +573,17 @@ _attributesAtIndexEffectiveRange(
{
NSZone *z = [self zone];
if (nil == aString)
{
[NSException raise: NSInvalidArgumentException
format: @"aString object passed to -[GSAttributedString initWithString:attributes:] is nil"];
}
if (![aString respondsToSelector: @selector(length)])
{
[NSException raise: NSInvalidArgumentException
format: @"aString object passed to -[GSAttributedString initWithString:attributes:] does not respond to -length"];
}
_infoArray = [[NSMutableArray allocWithZone: z] initWithCapacity: 1];
if (aString != nil && [aString isKindOfClass: [NSAttributedString class]])
{