diff --git a/base/fs.cpp b/base/fs.cpp index 7ae6ef69e..2a3eaae6c 100644 --- a/base/fs.cpp +++ b/base/fs.cpp @@ -249,7 +249,22 @@ std::string fix_path_separators(const std::string& filename) { std::string result; result.reserve(filename.size()); - for (auto chr : filename) { + + size_t i = 0; + +#if LAF_WINDOWS + // Network paths can start with two backslashes + if (filename.size() >= 2 && + filename[0] == path_separator && // Check for equality to backslash (\), + filename[1] == path_separator) { // no for is_path_separator() + result.push_back(path_separator); + result.push_back(path_separator); + i += 2; + } +#endif + + for (; i= 2 && + path[1] == path_separator) { + fn.push_back(path_separator); + } +#endif + } + std::vector parts; split_string(path, parts, path_separators); diff --git a/base/fs_tests.cpp b/base/fs_tests.cpp index 26862ef13..b48f1e91c 100644 --- a/base/fs_tests.cpp +++ b/base/fs_tests.cpp @@ -41,7 +41,13 @@ TEST(FS, FixPathSeparators) const std::string sep(1, path_separator); EXPECT_EQ(sep, fix_path_separators("/")); EXPECT_EQ(sep, fix_path_separators("///")); + EXPECT_EQ(sep+"a"+sep, fix_path_separators("//a/")); EXPECT_EQ("a"+sep+"b"+sep, fix_path_separators("a///b/")); + +#if LAF_WINDOWS + EXPECT_EQ("\\\\hostname\\a\\b", fix_path_separators("\\\\hostname\\\\a/b")); + EXPECT_EQ("\\\\hostname\\b", fix_path_separators("\\\\/hostname\\b")); +#endif } TEST(FS, MakeDirectory) @@ -281,6 +287,11 @@ TEST(FS, NormalizePath) EXPECT_EQ(".."+sep+"..", normalize_path("../a/../..")); EXPECT_EQ("..", normalize_path("a/../..")); EXPECT_EQ(sep+"b", normalize_path("/a/../b")); + +#if LAF_WINDOWS + EXPECT_EQ("\\\\hostname\\b", normalize_path("\\\\hostname\\\\a/../b")); + EXPECT_EQ("\\\\hostname\\b\\a", normalize_path("\\\\/hostname\\b/a")); +#endif } #if COMPARE_WITH_STD_FS