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

URL.deletingLastPathComponent() should append .. in special cases #989

Merged
merged 1 commit into from
Oct 25, 2024

Conversation

jrflat
Copy link
Contributor

@jrflat jrflat commented Oct 18, 2024

If a URL's relative path is being resolved against a base URL, we should append ".." as a means of deleting the last path component in the following cases:

  • The relative path is empty
  • The last relative path component is "."
  • The last relative path component is ".."

Otherwise, we can just remove the last path component as normal.

@jrflat
Copy link
Contributor Author

jrflat commented Oct 18, 2024

@swift-ci please test

Tests/FoundationEssentialsTests/URLTests.swift Outdated Show resolved Hide resolved
XCTAssertEqual(relative.path, "/absolute/relative")

relative.deleteLastPathComponent()
checkBehavior(relative.relativePath, new: "", old: ".")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there scenarios where this difference between "" and "." would actually matter? The only thing I can think of is existing clients using the string literally somewhere else, so this change of behavior breaks their expectation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I don't feel too strongly about returning "" over ".", so I think I will make the change to return "." and maximize compatibility. I could see a client recursively calling .deletingLastPathComponent() until the relative path matches ".". I'll edit this PR and #988

We can do this while still accepting URL(string: "", relativeTo: base) initialization to pass all RFC 3986 examples.

@jrflat jrflat force-pushed the deleting-path-special-cases branch from 438494e to 3eef139 Compare October 23, 2024 22:39
@jrflat
Copy link
Contributor Author

jrflat commented Oct 23, 2024

@swift-ci please test

@jrflat jrflat merged commit 5a497cc into swiftlang:main Oct 25, 2024
3 checks passed
jrflat added a commit to jrflat/swift-foundation that referenced this pull request Oct 29, 2024
jrflat added a commit that referenced this pull request Nov 4, 2024
cthielen pushed a commit to cthielen/swift-foundation that referenced this pull request Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants