瀏覽代碼

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

Fix #297
Pierre-Olivier Latour 8 年之前
父節點
當前提交
b4927bdd75
共有 1 個文件被更改,包括 3 次插入0 次删除
  1. 3 0
      GCDWebServer/Core/GCDWebServerConnection.m

+ 3 - 0
GCDWebServer/Core/GCDWebServerConnection.m

@@ -300,6 +300,9 @@ NS_ASSUME_NONNULL_END
             GWS_DCHECK(requestURL);
           }
           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* 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) : @{};