[google-toolbox-for-mac] r612 committed - Fix bug in GTMURLBuilder that doesn't handle url path with escaped cha...

7 views
Skip to first unread message

google-tool...@googlecode.com

unread,
May 6, 2013, 5:30:20 PM5/6/13
to google-tool...@googlegroups.com
Revision: 612
Author: gtm.daemon
Date: Mon May 6 14:30:09 2013
Log: 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)
http://code.google.com/p/google-toolbox-for-mac/source/detail?r=612

Modified:
/trunk/Foundation/GTMURLBuilder.m
/trunk/Foundation/GTMURLBuilderTest.m

=======================================
--- /trunk/Foundation/GTMURLBuilder.m Wed Jul 25 05:00:21 2012
+++ /trunk/Foundation/GTMURLBuilder.m Mon May 6 14:30:09 2013
@@ -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]]
=======================================
--- /trunk/Foundation/GTMURLBuilderTest.m Wed Jul 25 05:00:21 2012
+++ /trunk/Foundation/GTMURLBuilderTest.m Mon May 6 14:30:09 2013
@@ -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
Reply all
Reply to author
Forward
0 new messages