apollo-ios
apollo-ios copied to clipboard
URL construction fails with umlauts in string
Bug report
When receiving a url string from the server containing special characters like umlauts ü
, ä
the URL initialisation fails and therefore the decoding.
let urlString = "https://zürich.ch/"
guard let url = URL(string: urlString) else {
fatalError("Could not construct URL")
}
print(url)
Will producte Fatal error: Could not construct URL
This can easily be fixed using addingPercentageEncoding
let urlString = "https://zürich.ch/"
let sanitizedURLString = urlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
guard let sanitizedURLString = sanitizedURLString, let url = URL(string: sanitizedURLString) else {
fatalError("Could not construct URL")
}
print(url)
Will produce https://z%C3%BCrich.ch/
Versions
Please fill in the versions you're currently using:
-
apollo-ios
SDK version: 0.50.0 - Xcode version: 13.4
- Swift version: 5.5
- Package manager: SPM
Thanks for the bug report @Arestronaut. Is this specifically a problem only when receiving URLs from the server or also if you try connect to a URL with special characters in it?