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

Deleting last path component on Linux can result in URL with empty path #980

Open
ahoppen opened this issue Oct 11, 2024 · 0 comments
Open

Comments

@ahoppen
Copy link
Member

ahoppen commented Oct 11, 2024

var url = URL(fileURLWithPath: "/whatever/test.swift")
print("'\(url.path)'") // prints '/whatever/test.swift'
url.deleteLastPathComponent()
print("'\(url.path)'") // prints '/whatever'
url.deleteLastPathComponent()
print("'\(url.path)'") // prints ''

url = URL(fileURLWithPath: "/test.swift")
print("'\(url.path)'") // prints '/test.swift'
url.deleteLastPathComponent()
print("'\(url.path)'") // prints '/'

Where it prints '' at the end of the first section, I think it should print /.

This is in a Swift 6.0 Linux docker image.

ahoppen added a commit to ahoppen/swift-format that referenced this issue Oct 11, 2024
Due to swiftlang/swift-foundation#980, the we may end up with a `path == ""` instead of `/`.

We didn’t catch this in the test because we only end up with an empty path when searching for a `.swift-format` file from a `.swift-file` that was not at the root of a directory.
ahoppen added a commit to ahoppen/swift-format that referenced this issue Oct 11, 2024
Due to swiftlang/swift-foundation#980, the we may end up with a `path == ""` instead of `/`.

We didn’t catch this in the test because we only end up with an empty path when searching for a `.swift-format` file from a `.swift-file` that was not at the root of a directory.
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

No branches or pull requests

1 participant