mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-02 22:42:45 +08:00
Fix and test coverage for base URLs containing a path
This commit is contained in:
@@ -28,15 +28,20 @@
|
||||
}
|
||||
|
||||
- (id)initWithBaseURLString:(NSString*)baseURLString resourcePath:(NSString*)resourcePath queryParams:(NSDictionary*)queryParams {
|
||||
// Ensure the resource path always has a leading slash
|
||||
if ([resourcePath length] > 0) {
|
||||
resourcePath = ([resourcePath characterAtIndex:0] != '/') ? [NSString stringWithFormat:@"/%@", resourcePath] : resourcePath;
|
||||
}
|
||||
NSString* resourcePathWithQueryString = RKPathAppendQueryParams(resourcePath, queryParams);
|
||||
NSURL *baseURL = [NSURL URLWithString:baseURLString];
|
||||
NSURL *completeURL = [NSURL URLWithString:resourcePathWithQueryString relativeToURL:baseURL];
|
||||
NSURL *completeURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", baseURL, resourcePathWithQueryString]];
|
||||
if (!completeURL) {
|
||||
[self release];
|
||||
return nil;
|
||||
}
|
||||
|
||||
// You can't safely use initWithString:relativeToURL: in a NSURL subclass, see http://www.openradar.me/9729706
|
||||
NSLog(@"Initialized the string: %@", [completeURL absoluteString]);
|
||||
self = [self initWithString:[completeURL absoluteString]];
|
||||
if (self) {
|
||||
_baseURLString = [baseURLString copy];
|
||||
|
||||
@@ -53,5 +53,10 @@
|
||||
assertThat([URL absoluteString], is(equalTo(@"http://restkit.org")));
|
||||
}
|
||||
|
||||
- (void)itShouldHandleBaseURLsWithAPath {
|
||||
RKURL* URL = [RKURL URLWithBaseURLString:@"http://restkit.org/this" resourcePath:@"/test" queryParams:nil];
|
||||
assertThat([URL absoluteString], is(equalTo(@"http://restkit.org/this/test")));
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user