Commit cae529385437a24094ef2997dbf546723f7fd1ee

Russell Belfer 2013-09-03T14:00:27

Fix resolving relative windows network paths

diff --git a/src/path.c b/src/path.c
index 50a990b..7c1ec2c 100644
--- a/src/path.c
+++ b/src/path.c
@@ -242,8 +242,8 @@ int git_path_root(const char *path)
 
 #ifdef GIT_WIN32
 	/* Are we dealing with a windows network path? */
-	else if ((path[0] == '/' && path[1] == '/') ||
-		(path[0] == '\\' && path[1] == '\\'))
+	else if ((path[0] == '/' && path[1] == '/' && path[2] != '/') ||
+		(path[0] == '\\' && path[1] == '\\' && path[2] != '\\'))
 	{
 		offset += 2;
 
diff --git a/tests-clar/core/path.c b/tests-clar/core/path.c
index 3006001..e584d61 100644
--- a/tests-clar/core/path.c
+++ b/tests-clar/core/path.c
@@ -538,7 +538,6 @@ void test_core_path__15_resolve_relative(void)
 	assert_resolve_relative(&buf, "a/b/", "a/b/.");
 
 	assert_resolve_relative(&buf, "/a/b/c", "///a/b/c");
-	assert_resolve_relative(&buf, "/a/b/c", "//a/b/c");
 	assert_resolve_relative(&buf, "/", "////");
 	assert_resolve_relative(&buf, "/a", "///a");
 	assert_resolve_relative(&buf, "/", "///.");
@@ -565,5 +564,20 @@ void test_core_path__15_resolve_relative(void)
 	cl_git_pass(git_buf_sets(&buf, "////.."));
 	cl_git_fail(git_path_resolve_relative(&buf, 0));
 
+	/* things that start with Windows network paths */
+#ifdef GIT_WIN32
+	assert_resolve_relative(&buf, "//a/b/c", "//a/b/c");
+	assert_resolve_relative(&buf, "//a/", "//a/b/..");
+	assert_resolve_relative(&buf, "//a/b/c", "//a/Q/../b/x/y/../../c");
+
+	cl_git_pass(git_buf_sets(&buf, "//a/b/../.."));
+	cl_git_fail(git_path_resolve_relative(&buf, 0));
+#else
+	assert_resolve_relative(&buf, "/a/b/c", "//a/b/c");
+	assert_resolve_relative(&buf, "/a/", "//a/b/..");
+	assert_resolve_relative(&buf, "/a/b/c", "//a/Q/../b/x/y/../../c");
+	assert_resolve_relative(&buf, "/", "//a/b/../..");
+#endif
+
 	git_buf_free(&buf);
 }