Last active
August 29, 2015 14:14
-
-
Save mikeabdullah/d2216fdb378a71c50626 to your computer and use it in GitHub Desktop.
Creating a Hit List URL with + symbols in query items properly encoded
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSURL *)hitListURLWithTaskTitle:(NSString *)title { | |
// Basic URL as a starting point | |
NSURLComponents *components = [NSURLComponents componentsWithString:@"thehitlist:///inbox/tasks"]; | |
components.queryItems = @[ | |
[NSURLQueryItem queryItemWithName:@"method" value:@"POST"], | |
[NSURLQueryItem queryItemWithName:@"title" value:title] | |
]; | |
// NSURLQueryItem has encoded any spaces as %20 which is fine | |
// But + symbols are untouched, which will be mis-interpreted | |
// So post-process to encode them ourselves | |
components.percentEncodedQuery = [components.percentEncodedQuery | |
stringByReplacingOccurrencesOfString:@"+" | |
withString:@"%2B"]; | |
return components.URL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment