From 53247eb0a1bbead66603837c3c71ec38e1244a62 Mon Sep 17 00:00:00 2001 From: "gtm.daemon" Date: Mon, 6 May 2013 21:30:09 +0000 Subject: 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) --- Foundation/GTMURLBuilder.m | 9 +++------ Foundation/GTMURLBuilderTest.m | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) (limited to 'Foundation') 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 -- cgit v1.2.3