aboutsummaryrefslogtreecommitdiff
path: root/Foundation
diff options
context:
space:
mode:
authorGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2013-05-06 21:30:09 +0000
committerGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2013-05-06 21:30:09 +0000
commit53247eb0a1bbead66603837c3c71ec38e1244a62 (patch)
tree20e4ed2f59b7fd5899929012deae3d87addfcf8d /Foundation
parenta5d6ae8f62622465a2f5f26b8880029793b2c35d (diff)
Fix bug in GTMURLBuilder that doesn't handle url path with escaped characters. E.g. http://www.google.com/path%3AA/path%3AB would become http://www.google.com/path%3AA/path%3AB/path:A/path:B
DELTA=20 (14 added, 3 deleted, 3 changed)
Diffstat (limited to 'Foundation')
-rw-r--r--Foundation/GTMURLBuilder.m9
-rw-r--r--Foundation/GTMURLBuilderTest.m14
2 files changed, 17 insertions, 6 deletions
diff --git a/Foundation/GTMURLBuilder.m b/Foundation/GTMURLBuilder.m
index 0956755..52ee12a 100644
--- a/Foundation/GTMURLBuilder.m
+++ b/Foundation/GTMURLBuilder.m
@@ -53,15 +53,12 @@
// NSURL does not work with ports.
baseURLString_ = [URL absoluteString];
- if ([URL path]) {
+ if ([URL query]) {
NSRange pathRange =
- [baseURLString_ rangeOfString:[URL path] options:NSBackwardsSearch];
+ [baseURLString_ rangeOfString:[URL query] options:NSBackwardsSearch];
if (pathRange.location != NSNotFound) {
- baseURLString_ = [baseURLString_ substringToIndex:pathRange.location];
+ baseURLString_ = [baseURLString_ substringToIndex:pathRange.location-1];
}
-
- baseURLString_ =
- [NSString stringWithFormat:@"%@%@", baseURLString_, [URL path]];
}
[baseURLString_ retain];
params_ = [[NSDictionary gtm_dictionaryWithHttpArgumentsString:[URL query]]
diff --git a/Foundation/GTMURLBuilderTest.m b/Foundation/GTMURLBuilderTest.m
index f6eb829..4c0f128 100644
--- a/Foundation/GTMURLBuilderTest.m
+++ b/Foundation/GTMURLBuilderTest.m
@@ -37,6 +37,18 @@
STAssertEqualStrings(@"http://google.com:8080/pathA/pathB?param=val",
[URLBuilder URLString], nil);
STAssertEqualStrings(@"val", [URLBuilder valueForParameter:@"param"], nil);
+
+ URLBuilder = [GTMURLBuilder builderWithString:
+ @"http://google.com:8080/path%3AA/pathB?param=val"];
+ STAssertEqualStrings(@"http://google.com:8080/path%3AA/pathB?param=val",
+ [URLBuilder URLString], nil);
+ STAssertEqualStrings(@"val", [URLBuilder valueForParameter:@"param"], nil);
+
+ URLBuilder = [GTMURLBuilder builderWithString:
+ @"http://google.com:8080/pathA/pathB%2F?param=val"];
+ STAssertEqualStrings(@"http://google.com:8080/pathA/pathB%2F?param=val",
+ [URLBuilder URLString], nil);
+ STAssertEqualStrings(@"val", [URLBuilder valueForParameter:@"param"], nil);
}
- (void)testMailToHandling {
@@ -92,6 +104,8 @@
STAssertEqualStrings(@"http://google.com/", [URLBuilder URLString], nil);
URLBuilder = [GTMURLBuilder builderWithString:@"http://google.com/pA/pB"];
STAssertEqualStrings(@"http://google.com/pA/pB", [URLBuilder URLString], nil);
+ URLBuilder = [GTMURLBuilder builderWithString:@"http://google.com/p%3AA/pB"];
+ STAssertEqualStrings(@"http://google.com/p%3AA/pB", [URLBuilder URLString], nil);
}
@end