From a8b8a347c1a9e98de55047715662308ab89efc0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Sun, 22 Mar 2020 23:20:54 +0100 Subject: [PATCH] Make Path::SetExtension("") not include a dot --- src/platform/platform.cpp | 6 ++++-- test/core/path/test.cpp | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/platform/platform.cpp b/src/platform/platform.cpp index f025c861..00854131 100644 --- a/src/platform/platform.cpp +++ b/src/platform/platform.cpp @@ -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; } diff --git a/test/core/path/test.cpp b/test/core/path/test.cpp index 92639564..86accf1f 100644 --- a/test/core/path/test.cpp +++ b/test/core/path/test.cpp @@ -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"); }