Avoid going out of bounds for special URL chars ending mail contents.

This commit is contained in:
Ludovic Marcotte
2013-02-05 16:11:37 -05:00
parent 43044bf88f
commit 49a2299414
+21 -12
View File
@@ -195,18 +195,27 @@ static int cssEscapingCount;
startLocation--;
matchRange.location = startLocation + 1;
currentUrlRange = [selfCopy _rangeOfURLInRange: matchRange];
if (![ranges hasRangeIntersection: currentUrlRange])
if (currentUrlRange.length > matchLength)
[newRanges addNonNSObject: &currentUrlRange
withSize: sizeof (NSRange)
copy: YES];
rest.location = NSMaxRange (currentUrlRange);
length = [selfCopy length];
rest.length = length - rest.location;
matchRange = [selfCopy rangeOfString: match
options: 0 range: rest];
// We avoid going out of bounds if the mail content actually finishes
// with the @ (or something else) character
if (matchRange.location < [selfCopy length])
{
currentUrlRange = [selfCopy _rangeOfURLInRange: matchRange];
if (![ranges hasRangeIntersection: currentUrlRange])
if (currentUrlRange.length > matchLength)
[newRanges addNonNSObject: &currentUrlRange
withSize: sizeof (NSRange)
copy: YES];
rest.location = NSMaxRange (currentUrlRange);
length = [selfCopy length];
rest.length = length - rest.location;
matchRange = [selfCopy rangeOfString: match
options: 0 range: rest];
}
else
{
matchRange.location = NSNotFound;
}
}
// Make the substitutions, keep track of the new offset