mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-05 09:39:09 +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];
|
||||
|
||||
Reference in New Issue
Block a user