NSURL(string:relativeTo:) does not properly construct URLs

Originator:stephen.tramer
Number:rdar://31615751 Date Originated:4/13/17
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 8.2.1
Classification:Serious Bug Reproducible:Always
 
Summary:
The last path component of the relative URL is always stripped when using this initializer.

Steps to Reproduce:
1. Launch `swift`
2. > import Foundation
3. > NSURL(string: "foo", relativeTo:URL(string:"http://base.com/foo/bar")!)!.absoluteString

Expected Results:
$R1: String? = "http://base.com/foo/bar/foo"

Actual Results:
$R1: String? = "http://base.com/foo/foo"

Version:
Xcode Version 8.2.1 (8C1002)
MacOS 10.12.4 (16E195)


Notes:
This affects the Objective-C API as well, since it is bridged.

Configuration:


Attachments:

Comments

I'd assume this is expected behavior as if I was at http://base.com/foo/bar and navigated to "foo". My resulting destination would be http://base.com/foo/foo


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!