Skip to content

Commit 28b56f0

Browse files
committed
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
1 parent 9994415 commit 28b56f0

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

XCode/Sources/HttpParser.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public class HttpParser {
2323
}
2424
let request = HttpRequest()
2525
request.method = statusLineTokens[0]
26-
let urlComponents = URLComponents(string: statusLineTokens[1])
26+
let encodedPath = statusLineTokens[1].addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? statusLineTokens[1]
27+
let urlComponents = URLComponents(string: encodedPath)
2728
request.path = urlComponents?.path ?? ""
2829
request.queryParams = urlComponents?.queryItems?.map { ($0.name, $0.value ?? "") } ?? []
2930
request.headers = try readHeaders(socket)

0 commit comments

Comments
 (0)