소스 검색

fix for URLComponents returning nil

* when path contains 'weird' characters (`[]`) URLComponents won't parse it, so the path will be nil
  * escaping the string with `urlQueryAllowed` character set fixes this issue
Nejc Vivod 7 년 전
부모
커밋
28b56f05f7
1개의 변경된 파일2개의 추가작업 그리고 1개의 파일을 삭제
  1. 2 1
      XCode/Sources/HttpParser.swift

+ 2 - 1
XCode/Sources/HttpParser.swift

@@ -23,7 +23,8 @@ public class HttpParser {
         }
         let request = HttpRequest()
         request.method = statusLineTokens[0]
-        let urlComponents = URLComponents(string: statusLineTokens[1])
+        let encodedPath = statusLineTokens[1].addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? statusLineTokens[1]
+        let urlComponents = URLComponents(string: encodedPath)
         request.path = urlComponents?.path ?? ""
         request.queryParams = urlComponents?.queryItems?.map { ($0.name, $0.value ?? "") } ?? []
         request.headers = try readHeaders(socket)