NSURLComponents returns an empty URL instead of nil when nothing is set

Originator:arthur
Number:rdar://25382891 Date Originated:03/28/16
Status:Open Resolved:No
Product:iOS SDK Product Version:9.3
Classification:Other Bug Reproducible:Always
 
Hi,

According to the documentation of the URL property on NSURLComponents, an instance of NSURLComponents that does not have any authority set should return a nil URL. In practice, this isn't the case.

Reference doc:
https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSURLComponents_class/#//apple_ref/occ/instp/NSURLComponents/URL

Reference text from doc:
If the components object has an authority component (user, password, host, or port) and a path component, then the path must either begin with "/" or be an empty string. Otherwise, this property contains nil.

If the NSURLComponentsdoes not have an authority component (user, password, host, or port) and has a path component, the path component must not start with "//". If it does, this property contains nil.



Now, some Sample Swift code that can be put into a playground:

// Start Code

import Foundation

let c = NSURLComponents()
c.URL //  Returns empty URL object (should be nil)
c.URL?.absoluteString // Returns empty string (should return nil)

// End Code

So, either the docs need to be changed to reflect actual functionality, or the API should be updated to reflect what the docs actually state.

Steps to Reproduce:
In a Playground or sample app, do the following:

import Foundation

let c = NSURLComponents()
c.URL //  Returns empty URL object (should be nil)
c.URL?.absoluteString // Returns empty string (should return nil)

// End Code

Expected Results:
According to the documentation, c.URL should return nil and so should c.URL?.absoluteString.

Actual Results:
c.URL and c.URL?.absoluteString return empty objects

Version:
iOS 9.3

Notes:


Configuration:
All Devices and Simulators

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!