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-6527] Linux: Empty URLComponents does not generate valid URL #3774

Open
mbrandonw opened this issue Dec 4, 2017 · 2 comments
Open

[SR-6527] Linux: Empty URLComponents does not generate valid URL #3774

mbrandonw opened this issue Dec 4, 2017 · 2 comments

Comments

@mbrandonw
Copy link

Previous ID SR-6527
Radar None
Original Reporter @mbrandonw
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug, Linux
Assignee None
Priority Medium

md5: 22fd63926de4684cc07b905a8d223d78

Issue Description:

This code:

    let baseUrl = URL(string: "https://www.pointfree.co")
    let urlComponents = URLComponents()
    let url = urlComponents.url(relativeTo: baseUrl)

generates a valid `URL` on Darwin, but generates `nil` on Linux.

I am using Xcode 9.2 beta 9C34b, Swift 4.0.3

@pushkarnk
Copy link
Collaborator

This is interesting.

`urlComponents.url(relativeTo: baseUrl)` uses `urlComponents.string` which evaluates to an empty string (on both Linux and Darwin) and passes it to `URL(string:relativeTo)` which is expected to return nil if `string` is empty.

So, the `URLComponents.url(relativeTo)` implementation is a composition of `urlComponents.string` and `URL(string:relativeTo)` both of which are behaving as expected. May be it needs an alternate implementation?

@pushkarnk
Copy link
Collaborator

https://developer.apple.com/documentation/foundation/urlcomponents/1780048-url does not discuss the case of URLComponents value where nothing is defined. May be we should simply add a special case to make the behaviour same as Darwin.

@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
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

2 participants