Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-9900] NS/URLRequest.url behavior differs between Darwin and Linux for relative URL's #3540

Closed
swift-ci opened this issue Feb 11, 2019 · 5 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-9900
Radar None
Original Reporter morlovich (JIRA User)
Type Bug
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee morlovich (JIRA)
Priority Medium

md5: 08f9a1361d058da4c1f91e5e024291c0

Issue Description:

While debugging an issue when using Alamofire 5 on Linux I discovered the root cause to be a difference in behavior between Darwin and Linux Foundation when retrieving a url from an existing URLRequest (or NSURLRequest) for relative URL's. Consider the following code:

import Foundation

let baseUrl = URL(string: "http://httpbin.org")
let url = URL(string: "/get", relativeTo: baseUrl)!

print("url = (url)")
print("base = (url.baseURL!)")
print("relativeString = (url.relativeString)")
var req = URLRequest(url: url)
print("req.url = (req.url!)")
req.url = url
print("req.url = (req.url!)")

var nsreq = NSURLRequest(url: url)
print("nsreq.url = (nsreq.url!)")

Darwin output:
url = /get – http://httpbin.org
base = http://httpbin.org
relativeString = /get
req.url = http://httpbin.org/get
// reassignment happens here
req.url = /get – http://httpbin.org
nsreq.url = http://httpbin.org/get

Ubuntu output:
url = /get – http://httpbin.org
base = http://httpbin.org
relativeString = /get
req.url = /get – http://httpbin.org
// reassignment happens here
req.url = /get – http://httpbin.org
nsreq.url = /get – http://httpbin.org

Notice the difference in output. It looks like the .url property on Darwin is assigned a resolved absolute URL when NSURLRequest and URLRequest objects are constructed, however, a reassignment to .url property preserves the relative URL.

@swift-ci
Copy link
Contributor Author

Comment by Maksim Orlovich (JIRA)

ianpartridge (JIRA User), @parkera, @phausler, @spevans, @millenomi, @jshier What do you think is the best approach to fix this? I am inclined to fix this in the Foundation to make behavior match between OSX and Linux. Does the swift-4.2 branch still accept fixes? Thanks!

@spevans
Copy link
Collaborator

spevans commented Feb 11, 2019

For Foundation, if there is a difference between macOS and Linux and no obvious bug on the macOS side, the Linux behaviour is altered to match macOS as it is assumed to be the default correct way of working.

The swift-4.2 branch is still open for various bug fixes but any fix would go into the master branch first.

@swift-ci
Copy link
Contributor Author

Comment by Ian Partridge (JIRA)

Yes at first glance this looks like a bug in swift-corelibs-foundation.

@parkera
Copy link
Member

parkera commented Feb 13, 2019

Let's get a fix into master then we can cherry-pick it back to the 4.2 branch.

@spevans
Copy link
Collaborator

spevans commented Apr 26, 2019

#2180

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants