From 49daf24193eed76bad2114cfe8264e3bc2381bd4 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 21 Jun 2024 00:15:07 +0200 Subject: [PATCH] Path: small adjustments to `getAbsolutePath()` Windows implementation to match Linux one --- lib/path.cpp | 5 +++++ test/testpath.cpp | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/lib/path.cpp b/lib/path.cpp index 20f94b556291..0ada0733cbaf 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -357,11 +357,16 @@ bool Path::isHeader(const std::string &path) std::string Path::getAbsoluteFilePath(const std::string& filePath) { + if (filePath.empty()) + return ""; + std::string absolute_path; #ifdef _WIN32 char absolute[_MAX_PATH]; if (_fullpath(absolute, filePath.c_str(), _MAX_PATH)) absolute_path = absolute; + if (absolute_path.back() == '\\') + absolute_path.pop_back(); #elif defined(__linux__) || defined(__sun) || defined(__hpux) || defined(__GNUC__) || defined(__CPPCHECK__) // simplify the path since any non-existent part has to exist even if discarded by ".." std::string spath = Path::simplifyPath(filePath); diff --git a/test/testpath.cpp b/test/testpath.cpp index b161d23b0a23..69608af75433 100644 --- a/test/testpath.cpp +++ b/test/testpath.cpp @@ -464,8 +464,13 @@ class TestPath : public TestFixture { ASSERT_EQUALS(cwd_up, Path::getAbsoluteFilePath(Path::join(cwd, ".\\..\\"))); ASSERT_EQUALS(cwd, Path::getAbsoluteFilePath(".")); +#ifndef _WIN32 TODO_ASSERT_EQUALS(cwd, "", Path::getAbsoluteFilePath("./")); TODO_ASSERT_EQUALS(cwd, "", Path::getAbsoluteFilePath(".\\")); +#else + ASSERT_EQUALS(cwd, Path::getAbsoluteFilePath("./")); + ASSERT_EQUALS(cwd, Path::getAbsoluteFilePath(".\\")); +#endif ASSERT_EQUALS("", Path::getAbsoluteFilePath("")); @@ -475,6 +480,8 @@ class TestPath : public TestFixture { #else ASSERT_EQUALS(Path::toNativeSeparators(Path::join(cwd, "testabspath2.txt")), Path::getAbsoluteFilePath("testabspath2.txt")); #endif + + // TODO: test with symlinks } };