Skip to content
This repository has been archived by the owner on Feb 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #120 from adamjuhasz/master
Browse files Browse the repository at this point in the history
If protocol is not found, validProtocols still matches
  • Loading branch information
Sebastien C. Thiebaud committed Nov 24, 2014
2 parents 3a49670 + 172067a commit b36d774
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion STTweetLabel/STTweetLabel.m
Expand Up @@ -181,7 +181,7 @@ - (void)determineLinks {
[regex enumerateMatchesInString:tmpText options:0 range:NSMakeRange(0, tmpText.length) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
NSString *protocol = @"http";
NSString *link = [tmpText substringWithRange:result.range];
NSRange protocolRange = [link rangeOfString:@"://"];
NSRange protocolRange = [link rangeOfString:@":"];
if (protocolRange.location != NSNotFound) {
protocol = [link substringToIndex:protocolRange.location];
}
Expand Down
14 changes: 14 additions & 0 deletions STTweetLabelExample/STTweetLabel Tests/STTweetLabel_Tests.m
Expand Up @@ -349,4 +349,18 @@ - (void)test_setTextAndGetHotWords_setTextWithOnlyHashtagSymbol_hotWords
[self initiateTestFromSample:string results:results];
}

- (void)test_setTextAndGetHotWords_setTextWithTwoLinksOneValidAndOneNonvalidProtocol_hotWords
{
NSArray *originalValidProtocols = _tweetLabel.validProtocols;
_tweetLabel.validProtocols = @[@"mailto"];

NSString *string = @"This is a sample test with fail:page mailto:good@email.com";
NSArray *results = @[
@{@"hotWord": @(STTweetLink), @"range": [NSValue valueWithRange:NSMakeRange(37, 21)], @"protocol": @"mailto"}
];
[self initiateTestFromSample:string results:results];

_tweetLabel.validProtocols = originalValidProtocols;
}

@end

0 comments on commit b36d774

Please sign in to comment.