NSURL initWithScheme:host:path: gives unexpected absolute URL

Originator:dwood
Number:rdar://6870881 Date Originated:08-May-2009
Status:Open Resolved:
Product:Mac OS X Product Version:10.5.6
Classification:Serious Bug Reproducible:Always
 
Summary: 
An NSURL created with -[NSURL initWithScheme:host:path:] where the path is "/" returns *double* slashes at the end when you ask for its absoluteURL.

Steps to Reproduce:
1. In code, create an NSURL like this:
NSURL *theURL = [[NSURL alloc] initWithScheme:@"http" host:@"www.apple.com" path:@"/"];

2. Ask the URL for its absoluteString

Expected Results:
The URL should look like this:
http://www.apple.com/

Actual Results:
It looks like this -- note the double /
http://www.apple.com//

Regression:
I've tried passing in NULL or @"" to the path parameter but those are illegal and trigger an exception.

Notes:
Interestingly, when I query the URL for its path, it returns "/" - just as a URL created from a string with -[NSURL initWithString:@"http://www.apple.com/" does.  So why is it showing the extra slash when I ask for its absolute URL?  Is there a work-around to create the URL properly so that its absolute string only shows the single trailing slash?

Comments

Additional information submitted:

I found some more strange behaviors.

If you create a URL using this technique and give it @"/developer/" as the path, you would expect the resulting URL to be like:

http://www.example.com/developer/

but instead it is:

http://www. example.com/developer///

So in this case there are three trailing slashes, not one as I would expect.

In this case, when I query the created URL for its path, I get:

/developer//

So it's like an extra slash has been added when creating the URL, and another slash is added on output.

What gives?


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!