-
Notifications
You must be signed in to change notification settings - Fork 210
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
Passing in an empty array of query items to URL.appending(queryItems: [URLQueryItem]) adds a ? to the end of the url. Resulting in a potentially invalid URL.
To Reproduce
let url = "www.google.com"
let updatedUrl = url.appending(queryItems: [])
print(updatedUrl) // "www.google.com?"Expected behavior
If no query items are provided, the url should not be changed.
Configuration (please complete the following information):
- Swift Version: 6.2 (Xcode 26.1 beta 2)
- OS: iOS
- OS Version: iOS 26.0.1
Regression information:
n/a
Additional context
Probably a minor issue, but I am currently building out an HTTP Client package for my current job.
I had to write an extension on url to get around this issue:
public extension HTTPRequest {
private func constructURL(from baseURL: URL) -> URL {
var url = baseURL.appending(path: path)
if !queryItems.isEmpty {
url = url.appending(queryItems: queryItems)
}
return url
}
}instead of being able to rely on:
var url = baseURL.appending(path: path).appending(queryItems: queryItems)Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working