Browse Source

Fixed CFURLCopyPath() returning NULL for "//" path

Fix #297
Pierre-Olivier Latour 8 years ago
parent
commit
b4927bdd75
1 changed files with 3 additions and 0 deletions
  1. 3 0
      GCDWebServer/Core/GCDWebServerConnection.m

+ 3 - 0
GCDWebServer/Core/GCDWebServerConnection.m

@@ -300,6 +300,9 @@ NS_ASSUME_NONNULL_END
             GWS_DCHECK(requestURL);
             GWS_DCHECK(requestURL);
           }
           }
           NSString* urlPath = requestURL ? CFBridgingRelease(CFURLCopyPath((CFURLRef)requestURL)) : nil;  // Don't use -[NSURL path] which strips the ending slash
           NSString* urlPath = requestURL ? CFBridgingRelease(CFURLCopyPath((CFURLRef)requestURL)) : nil;  // Don't use -[NSURL path] which strips the ending slash
+          if (urlPath == nil) {
+            urlPath = @"/";  // CFURLCopyPath() returns NULL for a relative URL with path "//" contrary to -[NSURL path] which returns "/"
+          }
           NSString* requestPath = urlPath ? GCDWebServerUnescapeURLString(urlPath) : nil;
           NSString* requestPath = urlPath ? GCDWebServerUnescapeURLString(urlPath) : nil;
           NSString* queryString = requestURL ? CFBridgingRelease(CFURLCopyQueryString((CFURLRef)requestURL, NULL)) : nil;  // Don't use -[NSURL query] to make sure query is not unescaped;
           NSString* queryString = requestURL ? CFBridgingRelease(CFURLCopyQueryString((CFURLRef)requestURL, NULL)) : nil;  // Don't use -[NSURL query] to make sure query is not unescaped;
           NSDictionary* requestQuery = queryString ? GCDWebServerParseURLEncodedForm(queryString) : @{};
           NSDictionary* requestQuery = queryString ? GCDWebServerParseURLEncodedForm(queryString) : @{};