Browse files

Merge pull request #401 from syntheticpp/win-network-path

on windows a network path starts with two backslashes
  • Loading branch information...
2 parents 5fe8c13 + ee44a51 commit 413103c4c472410c10da179a841b5e3b05e576c0 @evmar evmar committed Aug 17, 2012
Showing with 27 additions and 0 deletions.
  1. +11 −0 src/util.cc
  2. +16 −0 src/util_test.cc
View
11 src/util.cc
@@ -110,8 +110,19 @@ bool CanonicalizePath(char* path, size_t* 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) {
View
16 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) {

0 comments on commit 413103c

Please sign in to comment.