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 path extension APIs should strip trailing slashes #965

Merged
merged 1 commit into from
Oct 7, 2024

Conversation

jrflat
Copy link
Contributor

@jrflat jrflat commented Oct 7, 2024

When supplying a directory to URL like URL(filePath: "/my/directory", directoryHint: .checkFileSystem), the initializer will automatically append a trailing slash, so the .path() is /my/directory/.

The current logic for .appendingPathExtension("zip") then directly appends the path extension, creating the unexpected path: /my/directory/.zip. A similar issue occurs where .deletingPathExtension() does not search before the trailing slash.

This PR restores the behavior from before the Swift URL implementation, which strips the trailing slash before appending or deleting the path extension, then appends a slash if the path was a directory. E.g. after appending the path extension, the resulting .path() is now /my/directory.zip/ as expected.

@jrflat jrflat requested review from parkera and jmschonfeld October 7, 2024 03:54
@jrflat
Copy link
Contributor Author

jrflat commented Oct 7, 2024

@swift-ci please test

@jrflat jrflat merged commit 09bdd0d into swiftlang:main Oct 7, 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