don't mangle absolute paths in the canonicalizer
authorEvan Martin <martine@danga.com>
Tue, 17 May 2011 23:35:32 +0000 (16:35 -0700)
committerEvan Martin <martine@danga.com>
Tue, 17 May 2011 23:35:32 +0000 (16:35 -0700)
We frequently do use absolute paths when depfiles refer to
e.g. /usr/include/stdio.h.

src/util.cc
src/util_test.cc

index e48c2775d4db110b97761df7ccc93be9b7d2d85c..63d3800b58169cfc9c40888b582d6040aed36275 100644 (file)
@@ -79,7 +79,7 @@ bool CanonicalizePath(string* path, string* err) {
     string::size_type end = path->find('/', start);
     if (end == string::npos)
       end = path->size();
-    if (end > start) {
+    if (end == 0 || end > start) {
       if (parts_count == kMaxPathComponents) {
         *err = "can't canonicalize path '" + *path + "'; too many "
             "path components";
index 4b4c7604b92ac388522763edd3dabe0b060e3259..87b614c5d52033643cc36b8bba3031e24933ae84 100644 (file)
@@ -53,3 +53,11 @@ TEST(CanonicalizePath, PathSamples) {
   EXPECT_EQ("can't canonicalize path './x/../foo/../../bar.h' that reaches "
             "above its directory", err);
 }
+
+TEST(CanonicalizePath, AbsolutePath) {
+  string path = "/usr/include/stdio.h";
+  string err = "";
+  EXPECT_TRUE(CanonicalizePath(&path, &err));
+  EXPECT_EQ("", err);
+  EXPECT_EQ("/usr/include/stdio.h", path);
+}