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-14145] URL.standardized turns a path in to a hostname #3234

Open
karwa opened this issue Feb 2, 2021 · 3 comments
Open

[SR-14145] URL.standardized turns a path in to a hostname #3234

karwa opened this issue Feb 2, 2021 · 3 comments

Comments

@karwa
Copy link
Contributor

karwa commented Feb 2, 2021

Previous ID SR-14145
Radar rdar://problem/73985908
Original Reporter @karwa
Type Bug
Environment

macOS 10.15.7 (19H15), Xcode Version 12.4 (12D4e)

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee pranavShenoy95 (JIRA)
Priority Medium

md5: e7bc5ade3f1a64f4d6c23af5d001611b

Issue Description:

For example, when parsing the string "swiftc/..///swift" relative to the base URL "file:///usr/bin/".

print(URL(string: "swiftc/..///swift", relativeTo: URL(string: "file:///usr/bin/")!)!.absoluteURL) 

file:///usr/bin///swift
print(URL(string: "swiftc/..///swift", relativeTo: URL(string: "file:///usr/bin/")!)!.standardized.absoluteURL) 

file://swift

Inspecting the latter shows that we have somehow managed to change the hostname of the URL. This is a bit surprising, given the documentation for standardized, which only says that it is "A version of the URL with any instances of “..” or “.” removed from its path."

@typesanitizer
Copy link

@swift-ci create

@swift-ci
Copy link
Contributor

Comment by pranav (JIRA)

@karwa Looks like "standardizedFileURL" should be used here since the URL is a file URL I am getting the URL as expected (

https://usr/bin//swift\n") while using this option.

Please let me know if the same must be obtained even while using "standardized"

@karwa
Copy link
Contributor Author

karwa commented Mar 30, 2021

pranavShenoy95 (JIRA User) The same happens with non-file URLs:

print(URL(string: "swiftc/..///swift", relativeTo: URL(string: "foo:///usr/bin/")!)!.standardized.absoluteURL)

foo://swift

My guess is that Foundation is removing the slashes in the string, treating it like a path, and inadvertently creating a protocol-relative URL string (https://en.wikipedia.org/wiki/URL#prurl)

IMO, this is outside of the documented behaviour for 'standardized', which says that it affects the URL's 'path'.

@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

3 participants