From 4104e5b18bfcc21c54ab42361ad8b1ed60b2ad8b Mon Sep 17 00:00:00 2001 From: Christoph Lehmann <christoph.lehmann@ufz.de> Date: Wed, 27 Jul 2016 16:54:33 +0200 Subject: [PATCH] [BL] change joinPaths no special behaviour if second path starts with dot the old behaviour could cause problems with unix' hidden files or with parent directories (..) --- BaseLib/FileTools.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/BaseLib/FileTools.cpp b/BaseLib/FileTools.cpp index 6f60be1b858..75525033b2c 100644 --- a/BaseLib/FileTools.cpp +++ b/BaseLib/FileTools.cpp @@ -141,11 +141,11 @@ std::string extractPath(std::string const& pathname) return ""; return pathname.substr(0, pos + 1); } -static const char * pathSeparator = +static const char pathSeparator = #ifdef _WIN32 - "\\"; + '\\'; #else - "/"; + '/'; #endif std::string appendPathSeparator(std::string const& path) @@ -157,12 +157,18 @@ std::string appendPathSeparator(std::string const& path) std::string joinPaths(std::string const& pathA, std::string const& pathB) { - std::string tmpB(pathB); - if(tmpB.substr(0, 1) == ".") - tmpB = tmpB.substr(1); - if(tmpB.substr(0, 1) == pathSeparator) - tmpB = tmpB.substr(1); - return appendPathSeparator(pathA) + tmpB; + if (pathA.empty()) + return pathB; + + if (pathB.empty()) + return pathA; + + if (pathB.front() == pathSeparator) { + auto const tmpB = pathB.substr(1); + return appendPathSeparator(pathA) + tmpB; + } else { + return appendPathSeparator(pathA) + pathB; + } } } // end namespace BaseLib -- GitLab