Make Path::SetExtension("") not include a dot

pull/846/head
наб 2020-03-22 23:20:54 +01:00 committed by phkahler
parent f5086b62cc
commit a8b8a347c1
2 changed files with 5 additions and 2 deletions

View File

@ -185,8 +185,10 @@ Path Path::WithExtension(std::string ext) const {
if(dot != std::string::npos) {
withExt.raw.erase(dot);
}
withExt.raw += ".";
withExt.raw += ext;
if(!ext.empty()) {
withExt.raw += ".";
withExt.raw += ext;
}
return withExt;
}

View File

@ -83,6 +83,7 @@ TEST_CASE(extension) {
}
TEST_CASE(with_extension) {
CHECK_EQ_STR(Path::From("foo.bar").WithExtension("").raw, "foo");
CHECK_EQ_STR(Path::From("foo.bar").WithExtension("baz").raw, "foo.baz");
CHECK_EQ_STR(Path::From("foo").WithExtension("baz").raw, "foo.baz");
}