1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-19 10:50:24 -04:00

baseNameOf(): Remove all trailing slashes

This commit is contained in:
Robert Hensing 2024-03-24 01:38:22 +01:00
parent 754a15e2db
commit 9884018dfa
2 changed files with 11 additions and 1 deletions

View file

@ -128,7 +128,7 @@ std::string_view baseNameOf(std::string_view path)
return "";
auto last = path.size() - 1;
if (path[last] == '/' && last > 0)
while (last > 0 && path[last] == '/')
last -= 1;
auto pos = path.rfind('/', last);

View file

@ -151,6 +151,16 @@ namespace nix {
ASSERT_EQ(p1, "dir");
}
TEST(baseNameOf, trailingSlashes) {
auto p1 = baseNameOf("/dir//");
ASSERT_EQ(p1, "dir");
}
TEST(baseNameOf, absoluteNothingSlashNothing) {
auto p1 = baseNameOf("//");
ASSERT_EQ(p1, "");
}
/* ----------------------------------------------------------------------------
* isInDir
* --------------------------------------------------------------------------*/