From bae8254d22209e356e330f5606bbaab26bf0f5fb Mon Sep 17 00:00:00 2001 From: Michael Theall Date: Sat, 30 May 2020 17:42:21 -0500 Subject: [PATCH] Fix path building --- source/ftpSession.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/source/ftpSession.cpp b/source/ftpSession.cpp index ca0b44a..b797efd 100644 --- a/source/ftpSession.cpp +++ b/source/ftpSession.cpp @@ -234,15 +234,26 @@ std::string resolvePath (std::string_view const path_) /// \param args_ Child component std::string buildPath (std::string_view const cwd_, std::string_view const args_) { + std::string path; + // absolute path if (args_[0] == '/') - return std::string (args_); + path = std::string (args_); + // relative path + else + path = std::string (cwd_) + '/' + std::string (args_); - // root directory - if (cwd_.size () == 1) - return std::string (cwd_) + std::string (args_); + // coalesce consecutive slashes + auto it = std::begin (path); + while (it != std::end (path)) + { + if (it != std::begin (path) && *it == '/' && *std::prev (it) == '/') + it = path.erase (it); + else + ++it; + } - return std::string (cwd_) + '/' + std::string (args_); + return path; } /// \brief Build resolved path from a parent and child