mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 04:57:03 +00:00
CPString subtringWithRange: and rangeOfString:options:range now throws CPRangeException for out of bounds ranges.
This commit is contained in:
@@ -28,6 +28,8 @@
|
||||
@import "CPURL.j"
|
||||
@import "CPValue.j"
|
||||
|
||||
#define _CPMaxRange(aRange) ((aRange).location + (aRange).length)
|
||||
|
||||
/*!
|
||||
A case insensitive search
|
||||
@global
|
||||
@@ -297,6 +299,9 @@ var CPStringRegexSpecialCharacters = [
|
||||
*/
|
||||
- (CPString)substringWithRange:(CPRange)aRange
|
||||
{
|
||||
if (aRange.location < 0 || _CPMaxRange(aRange) > length)
|
||||
[CPException raise:CPRangeException reason:"aRange out of bounds"];
|
||||
|
||||
return substr(aRange.location, aRange.length);
|
||||
}
|
||||
|
||||
|
||||
@@ -417,6 +417,18 @@
|
||||
hitRange = [testString rangeOfString:@"i" options:0 range:CPMakeRange(10, 20)];
|
||||
[self assert:12 equals:hitRange.location message:@"search for 'i' in partial range (location)"];
|
||||
[self assert:1 equals:hitRange.length message:@"search for 'i' in partial range (position)"];
|
||||
|
||||
var sawException = false;
|
||||
try
|
||||
{
|
||||
hitRange = [testString rangeOfString:@"i" options:0 range:CPMakeRange(50, 60)];
|
||||
}
|
||||
catch (anException)
|
||||
{
|
||||
sawException = true;
|
||||
[self assert:CPRangeException equals:[anException name]];
|
||||
}
|
||||
[self assertTrue:sawException message:"expected CPRangeException"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user