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-15504] URL.standardized does not account for relative URLs #3355

Open
karwa opened this issue Nov 21, 2021 · 1 comment
Open

[SR-15504] URL.standardized does not account for relative URLs #3355

karwa opened this issue Nov 21, 2021 · 1 comment

Comments

@karwa
Copy link
Contributor

karwa commented Nov 21, 2021

Previous ID SR-15504
Radar None
Original Reporter @karwa
Type Bug
Environment

macOS 11.6, XCode 13.1 (13A1030d)

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: 2cc1da750e65dafceb48da71b218fd63

Issue Description:

It's just entirely broken. This example adapted from Foundation's test suite (NSURLWithString-parse-relative-basic-005):

let url = URL(string: "../joe/blow", relativeTo: URL(string: "http://example.com/foo/bar")!)!
print(url)                   // "../joe/blow -- http://example.com/foo/bar"
print(url.path)              // "/joe/blow"
print(url.standardized)      // "joe/blow -- http://example.com/foo/bar"
print(url.standardized.path) // "/foo/joe/blow"

What is happening here is that Foundation is standardising the relative portion of the path only, NOT the overall URL.

Typically, what "standardising" does is remove "." components, and other components which are popped by a subsequent "..". As the test shows, ".." components in the relative path portion may actually pop components from the base URL.

This is slightly similar to, but different from, https://bugs.swift.org/browse/SR-14145

'.standardized' is just far too naive in its whole approach. I don't expect these to be trivial fixes; the function may need to be substantially rewritten.

@karwa
Copy link
Contributor Author

karwa commented Nov 21, 2021

It's hard to find another library which implements the same standard as Foundation (most of them use newer standards), but I did find one: "URL Toolkit" in JS (https://github.com/tjenkinson/url-toolkit).

Testing it on jsfiddle, it agrees that "/foo/joe/blow" is wrong; the path should be "/joe/blow", like the non-standardised URL's path returns.

https://jsfiddle.net/ovk4gcpd/9/

@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

1 participant