fix multiple sequential slashes
authorScott Graham <scottmg@chromium.org>
Sat, 8 Nov 2014 19:25:03 +0000 (11:25 -0800)
committerScott Graham <scottmg@chromium.org>
Sat, 8 Nov 2014 19:25:03 +0000 (11:25 -0800)
src/manifest_parser_test.cc
src/util.cc
src/util_test.cc

index 1998a77..0668668 100644 (file)
@@ -319,7 +319,7 @@ TEST_F(ParserTest, CanonicalizePathsBackslashes) {
 "  command = cat $in > $out\n"
 "build ./out.o: cat ./bar/baz/../foo.cc\n"
 "build .\\out2.o: cat .\\bar/baz\\..\\foo.cc\n"
-"build .\\out3.o: cat .\\bar/baz\\..\\foo3.cc\n"
+"build .\\out3.o: cat .\\bar\\baz\\..\\foo3.cc\n"
 ));
 
   EXPECT_FALSE(state.LookupNode("./out.o"));
@@ -336,7 +336,7 @@ TEST_F(ParserTest, CanonicalizePathsBackslashes) {
   EXPECT_EQ(0, node->slash_bits());
   node = state.LookupNode("bar/foo3.cc");
   EXPECT_TRUE(node);
-  EXPECT_EQ(1, node->slash_bits());  // First seen determines slashes.
+  EXPECT_EQ(1, node->slash_bits());
 }
 #endif
 
index 6a9079e..9cf736e 100644 (file)
@@ -194,7 +194,7 @@ bool CanonicalizePath(char* path, size_t* len, string* err,
 
     if (*src == '/') {
       src++;
-      bits_offset++;
+      bits = ShiftOverBit(bits_offset, bits);
       continue;
     }
 
index 36f212e..d047d9c 100644 (file)
@@ -218,6 +218,21 @@ TEST(CanonicalizePath, SlashTracking) {
   EXPECT_TRUE(CanonicalizePath(&path, &err, &slash_bits));
   EXPECT_EQ("a/g/foo.h", path);
   EXPECT_EQ(1, slash_bits);
+
+  path = "a\\\\\\foo.h";
+  EXPECT_TRUE(CanonicalizePath(&path, &err, &slash_bits));
+  EXPECT_EQ("a/foo.h", path);
+  EXPECT_EQ(1, slash_bits);
+
+  path = "a/\\\\foo.h";
+  EXPECT_TRUE(CanonicalizePath(&path, &err, &slash_bits));
+  EXPECT_EQ("a/foo.h", path);
+  EXPECT_EQ(0, slash_bits);
+
+  path = "a\\//foo.h";
+  EXPECT_TRUE(CanonicalizePath(&path, &err, &slash_bits));
+  EXPECT_EQ("a/foo.h", path);
+  EXPECT_EQ(1, slash_bits);
 }
 
 #endif