Skip to content

Commit

Permalink
Merge pull request #401 from syntheticpp/win-network-path
Browse files Browse the repository at this point in the history
on windows a network path starts with two backslashes
  • Loading branch information
evmar committed Aug 17, 2012
2 parents 5fe8c13 + ee44a51 commit 413103c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/util.cc
Expand Up @@ -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) {
Expand Down
16 changes: 16 additions & 0 deletions src/util_test.cc
Expand Up @@ -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) {
Expand Down

0 comments on commit 413103c

Please sign in to comment.