Convert root dir to preferred separator in path::lexically_normal.

This is consistent with std::filesystem and behavior before
16bd89b7c0398d0dc5904148a865ef3fc3ece7ec.

Closes https://github.com/boostorg/filesystem/issues/200.
This commit is contained in:
Andrey Semashev 2021-07-20 11:42:55 +03:00
parent 9e5a3e231e
commit d418858839
2 changed files with 13 additions and 2 deletions

View File

@ -525,8 +525,17 @@ BOOST_FILESYSTEM_DECL path path::lexically_relative(path const& base) const
BOOST_FILESYSTEM_DECL path path::lexically_normal() const
{
const size_type root_path_size = find_root_path_size();
path normal(m_pathname.c_str(), m_pathname.c_str() + root_path_size);
size_type root_name_size = 0;
size_type root_dir_pos = find_root_directory_start(m_pathname, m_pathname.size(), root_name_size);
path normal(m_pathname.c_str(), m_pathname.c_str() + root_name_size);
size_type root_path_size = root_name_size;
if (root_dir_pos < m_pathname.size())
{
root_path_size = root_dir_pos + 1;
normal.m_pathname.push_back(preferred_separator);
}
size_type i = root_path_size, n = m_pathname.size();
// Skip redundant directory separators after the root directory

View File

@ -2304,6 +2304,8 @@ void lexically_normal_tests()
if (platform == "Windows")
{
BOOST_TEST_EQ(path("c:/foo/bar").lexically_normal().string(), "c:\\foo\\bar");
PATH_TEST_EQ(path("c:foo").lexically_normal().generic_path(), "c:foo");
PATH_TEST_EQ(path("c:..").lexically_normal().generic_path(), "c:..");
PATH_TEST_EQ(path("c:foo/..").lexically_normal().generic_path(), "c:");