Skip to content

Commit c38c3a3

Browse files
authored
Merge pull request #724 from quoid/fix/avoid-potential-thread-crashes
fix: further avoid potential thread crashes
2 parents 310f29e + 8fa365d commit c38c3a3

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

xcode/Shared/UrlPolyfill.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,18 @@ func jsLikeURL(_ urlString: String, baseString: String? = nil) -> [String: Strin
5252
guard let scheme = url.scheme else {
5353
return nil
5454
}
55+
var port = ""
56+
if let portInt = url.port { port = String(portInt) }
57+
if (scheme == "http" && port == "80") { port = "" }
58+
if (scheme == "https" && port == "443") { port = "" }
5559
/*
5660
The issue still exists as of macOS 14.4, iOS 17.0
5761
https://stackoverflow.com/questions/74445926/url-host-deprecated-but-replacement-crashes
5862
https://forums.swift.org/t/does-url-query-percentencoded-calls-url-host-percentencoded-under-the-hood/70452
5963
https://forums.developer.apple.com/forums/thread/722451
6064
*/
61-
guard let hostname = url.host else {
62-
return nil
63-
}
64-
var port = (url.port == nil) ? "" : String(url.port!)
65-
if (scheme == "http" && port == "80") { port = "" }
66-
if (scheme == "https" && port == "443") { port = "" }
67-
if #available(macOS 13.0, iOS 16.0, *) {
68-
// let hostname = url.host(percentEncoded: true) ?? ""
65+
if #available(macOS 15.0, iOS 18.0, *) {
66+
guard let hostname = url.host(percentEncoded: true) else { return nil }
6967
let host = (port == "") ? hostname : "\(hostname):\(port)"
7068
let query = url.query(percentEncoded: true) ?? ""
7169
let fragment = url.fragment(percentEncoded: true) ?? ""
@@ -83,6 +81,7 @@ func jsLikeURL(_ urlString: String, baseString: String? = nil) -> [String: Strin
8381
"username": url.user(percentEncoded: true) ?? ""
8482
]
8583
} else {
84+
guard let hostname = url.host else { return nil }
8685
let host = (port == "") ? hostname : "\(hostname):\(port)"
8786
let query = url.query ?? ""
8887
let fragment = url.fragment ?? ""

0 commit comments

Comments
 (0)