Skip to content

URL(filePath: path, directoryHint: .notDirectory) should strip trailing slashes #867

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

Merged
merged 1 commit into from
Aug 19, 2024

Conversation

jrflat
Copy link
Contributor

@jrflat jrflat commented Aug 16, 2024

If a user supplies a path with trailing slash(es) and hints that it's .notDirectory, we should take their word for it and strip all trailing slashes. While that user input is slightly contradictory, this was the behavior before the Swift URL implementation, and at least it maintains the following consistency for any path:

let url = URL(filePath: path, directoryHint: .notDirectory)
XCTAssertEqual(url.hasDirectoryPath, false)

@jrflat
Copy link
Contributor Author

jrflat commented Aug 16, 2024

@swift-ci please test

@jrflat
Copy link
Contributor Author

jrflat commented Aug 16, 2024

Windows failure is real, the trailing slashes are not being stripped because they're backslashes at that point in the code, will push a fix

@jrflat jrflat force-pushed the file-path-not-directory branch from ce098f7 to 203ac4c Compare August 17, 2024 01:52
@jrflat
Copy link
Contributor Author

jrflat commented Aug 17, 2024

@swift-ci please test

1 similar comment
@jrflat
Copy link
Contributor Author

jrflat commented Aug 17, 2024

@swift-ci please test

@jrflat jrflat requested a review from jmschonfeld August 19, 2024 17:36
@jrflat jrflat merged commit 37fd6b8 into swiftlang:main Aug 19, 2024
3 checks passed
jrflat added a commit to jrflat/swift-foundation that referenced this pull request Oct 8, 2024
@jrflat jrflat mentioned this pull request Oct 8, 2024
jrflat added a commit to jrflat/swift-foundation that referenced this pull request Oct 14, 2024
jrflat added a commit that referenced this pull request Oct 14, 2024
* (133878310) URL.fileSystemPath should drop all trailing slashes (#852)

* (133882014) URL(filePath: path, directoryHint: .notDirectory) should strip trailing slashes (#867)

* (137129292) URL(filePath:) should not treat "~" as absolute (#961)

* (137068266) URL.fileSystemPath should strip leading slash for Windows drive letters (#964)

* (137287143) URL path extension APIs should strip trailing slashes (#965)
jrflat added a commit that referenced this pull request Oct 14, 2024
* (133878310) URL.fileSystemPath should drop all trailing slashes (#852)

* (133882014) URL(filePath: path, directoryHint: .notDirectory) should strip trailing slashes (#867)

* (137129292) URL(filePath:) should not treat "~" as absolute (#961)

* (137068266) URL.fileSystemPath should strip leading slash for Windows drive letters (#964)

* (137287143) URL path extension APIs should strip trailing slashes (#965)
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