URLComponents don't correctly encode URLQueryItem

Originator:me
Number:rdar://50251414 Date Originated:April 26 2019
Status:Open Resolved:
Product:iOS + SDK Foundation Product Version:Xcode 10.2.1 (10E1001)
Classification:Other bug Reproducible:Always
 
Area:
Foundation

Summary:
URLComponents don't percentage encode `+` and `@` in URLComponents.
According to RFC 3986 (https://en.wikipedia.org/wiki/Percent-encoding) `+` and `@` are reserved characters and should be percentage escaped when used out of the reserved context to `%2B` and `%40` respectively.
But `URLComponents` is ignoring it.
I attached a Playground with a sample test.


Steps to Reproduce:
let queryItems = [URLQueryItem(name: "email", value: "me+test@apple.com")]
var urlComponents = URLComponents(url: URL(string: "https://apple.com")!, resolvingAgainstBaseURL: false)!
urlComponents.queryItems = queryItems

let url: String! = urlComponents.url?.absoluteString
let expected = "https://apple.com?email=me%2Btest%40apple.com"
print(url == expected)

Expected Results:
Print `true`

Actual Results:
Print `false`

Version/Build:
10.2.1 (10E1001)

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!