mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Added tests to highlight some problems of the current implementation of NSURLQueryItems and NSURLComponent. The tests passed on OSX.
This commit is contained in:
parent
d4dc2dafc9
commit
57f3dd66f6
2 changed files with 34 additions and 0 deletions
|
@ -339,6 +339,23 @@ GSPathHandling("right");
|
|||
PASS_EQUAL([rel absoluteString], @"data:,$2A", "relative data URL works");
|
||||
PASS_EQUAL([rel baseURL], nil, "Base URL of relative data URL is nil");
|
||||
|
||||
///NSURLQueryItem
|
||||
|
||||
//OSX behavior is to return query item with an empty string name
|
||||
NSURLQueryItem* item = [[NSURLQueryItem alloc] init];
|
||||
PASS_EQUAL(item.name, @"", "NSURLQueryItem.name should not be nil");
|
||||
PASS_EQUAL(item.value, nil, "NSURLQueryItem.value should be nil");
|
||||
|
||||
//OSX behavior is to return query item with an empty string name
|
||||
item = [[NSURLQueryItem alloc] initWithName:nil value:nil];
|
||||
PASS_EQUAL(item.name, @"", "NSURLQueryItem.name should not be nil");
|
||||
PASS_EQUAL(item.value, nil, "NSURLQueryItem.value should be nil");
|
||||
|
||||
item = [[NSURLQueryItem alloc] initWithName:@"myName" value:@"myValue"];
|
||||
PASS_EQUAL(item.name, @"myName", "NSURLQueryItem.name should not be nil");
|
||||
PASS_EQUAL(item.value, @"myValue", "NSURLQueryItem.value should be nil");
|
||||
|
||||
|
||||
[arp release]; arp = nil;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -81,6 +81,23 @@ int main()
|
|||
"set query to item containing ampersand")
|
||||
PASS_EQUAL([components percentEncodedQuery], @"%26",
|
||||
"percent encoded query item encodes ampersand")
|
||||
|
||||
//NSURLQueryItem percent encoding/decoding test
|
||||
NSString* urlString = @"http://domain/?%D0%90%D0%B0%D0%91%D0%B1=%D0%90%D0%B0%D0%91%D0%B1";
|
||||
NSString* cyrillicStr = @"\U00000410\U00000430\U00000411\U00000431";
|
||||
NSURLComponents* components = [NSURLComponents componentsWithString:urlString];
|
||||
NSURLQueryItem* item = [[components queryItems] lastObject];
|
||||
PASS_EQUAL(item.name, cyrillicStr, "Should return decoded query item name from url");
|
||||
PASS_EQUAL(item.value, cyrillicStr, "Should return decoded query item value from url");
|
||||
|
||||
item = [NSURLQueryItem queryItemWithName:cyrillicStr value:cyrillicStr];
|
||||
[components setQueryItems:[NSArray arrayWithObject:item]];
|
||||
PASS_EQUAL([components string], urlString, "Encoded url string from unencoded item");
|
||||
PASS_EQUAL([components URL], [NSURL URLWithString:urlString], "Encoded url query part from unencoded item");
|
||||
|
||||
NSString* invalidUrlString = @"\U00000410\U00000430\U00000411\U00000431";
|
||||
PASS_EQUAL([NSURL URLWithString:invalidUrlString], nil, "nil NSURL from invalid string")
|
||||
PASS_EQUAL([NSURLComponents componentsWithString:invalidUrlString], nil, "nil NSComponents from invalid string")
|
||||
|
||||
END_SET("components")
|
||||
|
||||
|
|
Loading…
Reference in a new issue