apollo-ios icon indicating copy to clipboard operation
apollo-ios copied to clipboard

URL construction fails with umlauts in string

Open Arestronaut opened this issue 2 years ago • 1 comments

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

Arestronaut avatar May 24 '22 10:05 Arestronaut

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?

calvincestari avatar May 27 '22 04:05 calvincestari