-
Notifications
You must be signed in to change notification settings - Fork 28
Make baseName consistent with C++17 filesystem::path::stem #281
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -135,7 +135,7 @@ class LocalPathName { | |||||||||
| std::string clusterName() const; | ||||||||||
|
|
||||||||||
| /// Base name of the path | ||||||||||
| /// @param ext if false the extension is stripped | ||||||||||
| /// @param ext if false only the final extension is stripped | ||||||||||
|
||||||||||
| /// @param ext if false only the final extension is stripped | |
| /// @param ext if false only the final extension is stripped. The leading '.' of a | |
| /// hidden file is not treated as an extension separator, e.g. `.hidden` stays | |
| /// `.hidden`, and `.hidden.tar.gz` becomes `.hidden.tar` when ext is false. |
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -255,6 +255,23 @@ CASE("Extract basename") { | |||||||||||
| LocalPathName p("/a/made/up/path/that/does/not/exist/file.ok"); | ||||||||||||
| EXPECT(p.baseName(false) == "file"); | ||||||||||||
| EXPECT(p.baseName(true) == "file.ok"); | ||||||||||||
|
|
||||||||||||
| // ECKIT-415: multi-dot filenames should strip only the final extension | ||||||||||||
| EXPECT(LocalPathName("/path/archive.tar.gz").baseName(false) == "archive.tar"); | ||||||||||||
| EXPECT(LocalPathName("/path/archive.tar.gz").baseName(true) == "archive.tar.gz"); | ||||||||||||
|
|
||||||||||||
| EXPECT(LocalPathName("file..txt").baseName(false) == "file."); | ||||||||||||
| EXPECT(LocalPathName("file..txt").baseName(true) == "file..txt"); | ||||||||||||
|
|
||||||||||||
|
||||||||||||
| // Trailing-dot filenames: strip only the final extension (empty extension case) | |
| EXPECT(LocalPathName("fred..").baseName(false) == "fred."); | |
| EXPECT(LocalPathName("fred..").baseName(true) == "fred.."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
baseName(false)now treats a leading '.' as not being an extension separator (e.g. ".hidden" stays ".hidden"), butextension()still returns the substring from the last '.', which makes.hiddenreport an extension of ".hidden". This is inconsistent with the new semantics (and withstd::filesystem), and can lead to surprising results if callers split/recombine usingbaseName(false)+extension(). Consider updatingextension()to return "" when the only dot is a leading dot (and adding/adjusting tests accordingly), or clearly documenting thatextension()treats leading dots differently.