Commit 71cf8a3a authored by Brad King's avatar Brad King Committed by Kitware Robot
Browse files

Merge topic 'SystemTools-CollapseFullPath-relative-base'

c6f8e24a SystemTools: Fix CollapseFullPath with relative base path
15896025

 SystemTools: Use C++11 in SystemToolsAppendComponents
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !145
parents e9fed49e c6f8e24a
......@@ -3394,15 +3394,16 @@ static void SystemToolsAppendComponents(
static const std::string cur = ".";
for (std::vector<std::string>::const_iterator i = first; i != last; ++i) {
if (*i == up) {
if (out_components.size() > 1) {
// Remove the previous component if possible. Ignore ../ components
// that try to go above the root. Keep ../ components if they are
// at the beginning of a relative path (base path is relative).
if (out_components.size() > 1 && out_components.back() != up) {
out_components.resize(out_components.size() - 1);
} else if (!out_components.empty() && out_components[0].empty()) {
out_components.emplace_back(std::move(*i));
}
} else if (!i->empty() && *i != cur) {
#if __cplusplus >= 201103L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201103L)
out_components.push_back(std::move(*i));
#else
out_components.push_back(*i);
#endif
out_components.emplace_back(std::move(*i));
}
}
}
......
......@@ -684,9 +684,10 @@ static bool CheckRelativePaths()
}
static bool CheckCollapsePath(const std::string& path,
const std::string& expected)
const std::string& expected,
const char* base = nullptr)
{
std::string result = kwsys::SystemTools::CollapseFullPath(path);
std::string result = kwsys::SystemTools::CollapseFullPath(path, base);
if (!kwsys::SystemTools::ComparePath(expected, result)) {
std::cerr << "CollapseFullPath(" << path << ") yielded " << result
<< " instead of " << expected << std::endl;
......@@ -710,6 +711,9 @@ static bool CheckCollapsePath()
res &= CheckCollapsePath("C:/", "C:/");
res &= CheckCollapsePath("C:/../", "C:/");
res &= CheckCollapsePath("C:/../../", "C:/");
res &= CheckCollapsePath("../b", "../../b", "../");
res &= CheckCollapsePath("../a/../b", "../b", "../rel");
res &= CheckCollapsePath("a/../b", "../rel/b", "../rel");
return res;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment