Skip to content

Instantly share code, notes, and snippets.

@tjw
Created March 18, 2013 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjw/5189498 to your computer and use it in GitHub Desktop.
Save tjw/5189498 to your computer and use it in GitHub Desktop.
Radar 13443089
#import <Foundation/Foundation.h>
/*
clang -Wall -O2 -fobjc-arc NSURLEncodingCase.m -framework Foundation -o NSURLEncodingCase
./NSURLEncodingCase 'https://localhost/test%5b' 'https://localhost/test%5B'
2013-03-18 11:04:42.663 NSURLEncodingCase[80520:707] https://localhost/test%5b is NOT equal https://localhost/test%5B
http://tools.ietf.org/html/rfc3986#section-2.1 says
"The uppercase hexadecimal digits 'A' through 'F' are equivalent to
the lowercase digits 'a' through 'f', respectively. If two URIs
differ only in the case of hexadecimal digits used in percent-encoded
octets, they are equivalent. For consistency, URI producers and
normalizers should use uppercase hexadecimal digits for all percent-
encodings."
NSURL's documentation says that it intentionaly violates RFC 3986:
"Two NSURLs are considered equal if and only if they return identical values for both baseURL and relativeString."
*/
int main(int argc, char *argv[])
{
if (argc != 3) {
fprintf(stderr, "usage: %s url1 url2\n", argv[0]);
return 1;
}
@autoreleasepool {
NSString *urlString1 = [NSString stringWithUTF8String:argv[1]];
NSString *urlString2 = [NSString stringWithUTF8String:argv[2]];
NSURL *url1 = [NSURL URLWithString:urlString1];
NSURL *url2 = [NSURL URLWithString:urlString2];
NSLog(@"url1 = %@ -- %@", [url1 baseURL], [url1 relativeString]);
NSLog(@"url2 = %@ -- %@", [url2 baseURL], [url2 relativeString]);
NSLog(@"%@ %@ %@", url1, [url1 isEqual:url2] ? @"is equal" : @"is NOT equal", url2);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment