From ee44a510f448d130948380bd26926d3b17f5f11d Mon Sep 17 00:00:00 2001 From: Peter Kuemmel Date: Thu, 16 Aug 2012 15:26:33 +0200 Subject: [PATCH] on windows a network path starts with two backslashes --- src/util.cc | 11 +++++++++++ src/util_test.cc | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/util.cc b/src/util.cc index 7c2f895..4bd34e6 100644 --- a/src/util.cc +++ b/src/util.cc @@ -110,8 +110,19 @@ bool CanonicalizePath(char* path, int* len, string* err) { const char* end = start + *len; if (*src == '/') { +#ifdef _WIN32 + // network path starts with // + if (*len > 1 && *(src + 1) == '/') { + src += 2; + dst += 2; + } else { + ++src; + ++dst; + } +#else ++src; ++dst; +#endif } while (src < end) { diff --git a/src/util_test.cc b/src/util_test.cc index 5ace5e7..17e2704 100644 --- a/src/util_test.cc +++ b/src/util_test.cc @@ -66,6 +66,22 @@ TEST(CanonicalizePath, PathSamples) { path = "foo/.hidden_bar"; EXPECT_TRUE(CanonicalizePath(&path, &err)); EXPECT_EQ("foo/.hidden_bar", path); + + path = "/foo"; + EXPECT_TRUE(CanonicalizePath(&path, &err)); + EXPECT_EQ("/foo", path); + + path = "//foo"; + EXPECT_TRUE(CanonicalizePath(&path, &err)); +#ifdef _WIN32 + EXPECT_EQ("//foo", path); +#else + EXPECT_EQ("/foo", path); +#endif + + path = "/"; + EXPECT_TRUE(CanonicalizePath(&path, &err)); + EXPECT_EQ("", path); } TEST(CanonicalizePath, EmptyResult) { -- 2.7.4