Commits

unicodemonkey  committed 1798fd6

path escaping (at last)

  • Participants
  • Parent commits 1ced318

Comments (0)

Files changed (1)

File Plugins/HTTPSource/Utils/HTTPConnection.m

 	return NO;
 }
 
+
+NSString* stringByAddingPercentEscapesForUrl(NSString *url)
+{
+	NSString *forceEscaped = NULL; // @";?:@&=+$,";
+	NSString *forceUnescaped = NULL;
+	return NSMakeCollectable(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, 
+																	 (CFStringRef)url, 
+																	 (CFStringRef)forceUnescaped,
+																	 (CFStringRef)forceEscaped, 
+																	 kCFStringEncodingUTF8));
+}
+
 - (BOOL)_sendRequest
 {
 	NSURL *url = [self URL];
 	
-	NSString *path = [url path];
-	if (nil == path || [path isEqualToString:@""]) {
-		path = @"/";
+	NSString *rawPath = [url path];
+	if (nil == rawPath) {
+		rawPath = @"/";
 	}
+	NSString *path = stringByAddingPercentEscapesForUrl(rawPath);
 	
 	// The initial GET
-	NSMutableString *requestString = [[NSMutableString alloc] initWithFormat:@"GET %@ HTTP/1.0\r\n", path];
+	NSMutableString *requestString = [[NSMutableString alloc] initWithFormat:@"GET %@%@ HTTP/1.0\r\n", 
+									  [path hasPrefix:@"/"] ? @"" : @"/",
+									  path];
+	[path release];
 	
 	// Make sure there is a Host entry
 	NSString *host = [url host];