Skip to content

Instantly share code, notes, and snippets.

@rui314
Created November 25, 2014 00:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rui314/2a3b97720812aff656ab to your computer and use it in GitHub Desktop.
Save rui314/2a3b97720812aff656ab to your computer and use it in GitHub Desktop.
diff --git a/src/util.cc b/src/util.cc
index 746d7ed..3a3c7df 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -190,6 +190,9 @@ bool CanonicalizePath(char* path, size_t* len, unsigned int* slash_bits,
bits_offset--;
bits = ShiftOverBit(bits_offset, bits);
#endif
+ } else if (*start == '/') {
+ src += 3;
+ dst = start + 1;
} else {
*dst++ = *src++;
*dst++ = *src++;
diff --git a/src/util_test.cc b/src/util_test.cc
index 8ca7f56..0ce1169 100644
--- a/src/util_test.cc
+++ b/src/util_test.cc
@@ -80,6 +80,10 @@ TEST(CanonicalizePath, PathSamples) {
EXPECT_TRUE(CanonicalizePath(&path, &err));
EXPECT_EQ("/foo", path);
+ path = "/../foo";
+ EXPECT_TRUE(CanonicalizePath(&path, &err));
+ EXPECT_EQ("/foo", path);
+
path = "//foo";
EXPECT_TRUE(CanonicalizePath(&path, &err));
#ifdef _WIN32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment