Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed that the URL string is not percentage escaped and checked for nil #22

Merged
merged 1 commit into from
Sep 27, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions TSMarkdownParser/TSMarkdownParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,17 @@ - (void)addLinkParsingWithFormattingBlock:(TSMarkdownParserFormattingBlock)forma
NSUInteger linkStartInResult = [attributedString.string rangeOfString:@"(" options:NSBackwardsSearch range:match.range].location;
NSRange linkRange = NSMakeRange(linkStartInResult, match.range.length+match.range.location-linkStartInResult-1);
NSString *linkURLString = [attributedString.string substringWithRange:NSMakeRange(linkRange.location+1, linkRange.length-1)];
NSURL *url = [NSURL URLWithString:linkURLString];
NSURL *url = [NSURL URLWithString:[linkURLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

NSUInteger linkTextEndLocation = [attributedString.string rangeOfString:@"]" options:0 range:match.range].location;
NSRange linkTextRange = NSMakeRange(match.range.location, linkTextEndLocation-match.range.location-1);

[attributedString deleteCharactersInRange:NSMakeRange(match.range.location, 1)];
[attributedString deleteCharactersInRange:NSMakeRange(linkRange.location-2, linkRange.length+2)];

[attributedString addAttribute:NSLinkAttributeName
value:url
range:linkTextRange];

if (url) {
[attributedString addAttribute:NSLinkAttributeName value:url range:linkTextRange];
}
formattingBlock(attributedString, linkTextRange);

}];
Expand Down