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

Removing the last path component of a standalone file path results in an empty path #922

Open
omochi opened this issue Sep 18, 2024 · 0 comments

Comments

@omochi
Copy link

omochi commented Sep 18, 2024

As described in the title, the following occurs:

import Foundation

let file = URL(fileURLWithPath: "main.swift")
let dir = file.deletingLastPathComponent()
print(dir.relativePath) // => 
print(dir.appendingPathComponent("main.swift").path) // => /main.swift

Since main.swift represents a relative path from the current directory, removing the last component should result in . to indicate the current directory. However, it incorrectly results in an empty path ``.

When combined with the bug #921, this behavior causes the path to change unexpectedly when re-adding the removed component, resulting in a different path from the original file.

On macOS, the result is . as expected, so re-adding the removed component restores the path to the original file.

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