Fix resolving relative windows network paths
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
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);
}