I assume that you use the NSURL
method
initWithScheme:host:path:
to create the URL. According to the documentation, this method automatically escapes path with the stringByAddingPercentEscapesUsingEncoding:
method.
The square brackets are escaped, because they are "unsafe" in the sense of RFC 1738 - Uniform Resource Locators (URL):
Characters can be unsafe for a number of reasons. [...] Other characters are unsafe because gateways and other transport agents are known to sometimes modify such characters. These characters are "{", "}", "|", "\", "^", "~", "[", "]", and "`".
All unsafe characters must always be encoded within a URL.
If you create the URL with
NSString *s = [NSString stringWithFormat:@"http://server.domain.com/sm/search?limit=100&term=%@&types[]=users&types[]=questions", searchTerm];
NSURL *url = [[NSURL alloc] initWithString:s];
then no escape sequences are added, because initWithString
expects the string to contain any necessary percent escape codes.