Merge pull request #2767 from linquize/winpath More Windows Path checking
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
diff --git a/src/path.c b/src/path.c
index 768a7e1..0bad962 100644
--- a/src/path.c
+++ b/src/path.c
@@ -1254,7 +1254,7 @@ GIT_INLINE(bool) verify_dospath(
if (len < last || git__strncasecmp(component, dospath, 3) != 0)
return true;
- if (trailing_num && !git__isdigit(component[3]))
+ if (trailing_num && (component[3] < '1' || component[3] > '9'))
return true;
return (len > last &&
diff --git a/tests/path/core.c b/tests/path/core.c
index 85fee82..5b110f6 100644
--- a/tests/path/core.c
+++ b/tests/path/core.c
@@ -203,6 +203,9 @@ void test_path_core__isvalid_dos_paths(void)
cl_assert_equal_b(true, git_path_isvalid(NULL, "aux.asdf", 0));
cl_assert_equal_b(true, git_path_isvalid(NULL, "aux.asdf\\zippy", 0));
cl_assert_equal_b(true, git_path_isvalid(NULL, "aux:asdf\\foobar", 0));
+ cl_assert_equal_b(true, git_path_isvalid(NULL, "con", 0));
+ cl_assert_equal_b(true, git_path_isvalid(NULL, "prn", 0));
+ cl_assert_equal_b(true, git_path_isvalid(NULL, "nul", 0));
cl_assert_equal_b(false, git_path_isvalid(NULL, "aux", GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(false, git_path_isvalid(NULL, "aux.", GIT_PATH_REJECT_DOS_PATHS));
@@ -210,6 +213,9 @@ void test_path_core__isvalid_dos_paths(void)
cl_assert_equal_b(false, git_path_isvalid(NULL, "aux.asdf", GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(false, git_path_isvalid(NULL, "aux.asdf\\zippy", GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(false, git_path_isvalid(NULL, "aux:asdf\\foobar", GIT_PATH_REJECT_DOS_PATHS));
+ cl_assert_equal_b(false, git_path_isvalid(NULL, "con", GIT_PATH_REJECT_DOS_PATHS));
+ cl_assert_equal_b(false, git_path_isvalid(NULL, "prn", GIT_PATH_REJECT_DOS_PATHS));
+ cl_assert_equal_b(false, git_path_isvalid(NULL, "nul", GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(true, git_path_isvalid(NULL, "aux1", 0));
cl_assert_equal_b(true, git_path_isvalid(NULL, "aux1", GIT_PATH_REJECT_DOS_PATHS));
@@ -225,6 +231,8 @@ void test_path_core__isvalid_dos_paths_withnum(void)
cl_assert_equal_b(true, git_path_isvalid(NULL, "com1.asdf", 0));
cl_assert_equal_b(true, git_path_isvalid(NULL, "com1.asdf\\zippy", 0));
cl_assert_equal_b(true, git_path_isvalid(NULL, "com1:asdf\\foobar", 0));
+ cl_assert_equal_b(true, git_path_isvalid(NULL, "com1\\foo", 0));
+ cl_assert_equal_b(true, git_path_isvalid(NULL, "lpt1", 0));
cl_assert_equal_b(false, git_path_isvalid(NULL, "com1", GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(false, git_path_isvalid(NULL, "com1.", GIT_PATH_REJECT_DOS_PATHS));
@@ -232,11 +240,18 @@ void test_path_core__isvalid_dos_paths_withnum(void)
cl_assert_equal_b(false, git_path_isvalid(NULL, "com1.asdf", GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(false, git_path_isvalid(NULL, "com1.asdf\\zippy", GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(false, git_path_isvalid(NULL, "com1:asdf\\foobar", GIT_PATH_REJECT_DOS_PATHS));
+ cl_assert_equal_b(false, git_path_isvalid(NULL, "com1/foo", GIT_PATH_REJECT_DOS_PATHS));
+ cl_assert_equal_b(false, git_path_isvalid(NULL, "lpt1", GIT_PATH_REJECT_DOS_PATHS));
+ cl_assert_equal_b(true, git_path_isvalid(NULL, "com0", 0));
+ cl_assert_equal_b(true, git_path_isvalid(NULL, "com0", GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(true, git_path_isvalid(NULL, "com10", 0));
cl_assert_equal_b(true, git_path_isvalid(NULL, "com10", GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(true, git_path_isvalid(NULL, "comn", GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(true, git_path_isvalid(NULL, "com1\\foo", GIT_PATH_REJECT_DOS_PATHS));
+ cl_assert_equal_b(true, git_path_isvalid(NULL, "lpt0", GIT_PATH_REJECT_DOS_PATHS));
+ cl_assert_equal_b(true, git_path_isvalid(NULL, "lpt10", GIT_PATH_REJECT_DOS_PATHS));
+ cl_assert_equal_b(true, git_path_isvalid(NULL, "lptn", GIT_PATH_REJECT_DOS_PATHS));
}
void test_path_core__isvalid_nt_chars(void)