]>
Commit | Line | Data |
---|---|---|
0ee9f31c | 1 | #include "clar_libgit2.h" |
e579e0f7 | 2 | #include "fs_path.h" |
0ee9f31c ET |
3 | #include "path.h" |
4 | ||
c25aa7cd PP |
5 | void test_path_core__cleanup(void) |
6 | { | |
7 | cl_git_sandbox_cleanup(); | |
8 | } | |
9 | ||
0ee9f31c ET |
10 | static void test_make_relative( |
11 | const char *expected_path, | |
12 | const char *path, | |
13 | const char *parent, | |
14 | int expected_status) | |
15 | { | |
e579e0f7 MB |
16 | git_str buf = GIT_STR_INIT; |
17 | git_str_puts(&buf, path); | |
18 | cl_assert_equal_i(expected_status, git_fs_path_make_relative(&buf, parent)); | |
0ee9f31c | 19 | cl_assert_equal_s(expected_path, buf.ptr); |
e579e0f7 | 20 | git_str_dispose(&buf); |
0ee9f31c ET |
21 | } |
22 | ||
23 | void test_path_core__make_relative(void) | |
24 | { | |
0ee9f31c ET |
25 | test_make_relative("foo.c", "/path/to/foo.c", "/path/to", 0); |
26 | test_make_relative("bar/foo.c", "/path/to/bar/foo.c", "/path/to", 0); | |
27 | test_make_relative("foo.c", "/path/to/foo.c", "/path/to/", 0); | |
28 | ||
29 | test_make_relative("", "/path/to", "/path/to", 0); | |
30 | test_make_relative("", "/path/to", "/path/to/", 0); | |
31 | ||
32 | test_make_relative("../", "/path/to", "/path/to/foo", 0); | |
33 | ||
34 | test_make_relative("../foo.c", "/path/to/foo.c", "/path/to/bar", 0); | |
35 | test_make_relative("../bar/foo.c", "/path/to/bar/foo.c", "/path/to/baz", 0); | |
36 | ||
37 | test_make_relative("../../foo.c", "/path/to/foo.c", "/path/to/foo/bar", 0); | |
38 | test_make_relative("../../foo/bar.c", "/path/to/foo/bar.c", "/path/to/bar/foo", 0); | |
39 | ||
40 | test_make_relative("../../foo.c", "/foo.c", "/bar/foo", 0); | |
41 | ||
42 | test_make_relative("foo.c", "/path/to/foo.c", "/path/to/", 0); | |
43 | test_make_relative("../foo.c", "/path/to/foo.c", "/path/to/bar/", 0); | |
44 | ||
45 | test_make_relative("foo.c", "d:/path/to/foo.c", "d:/path/to", 0); | |
46 | ||
47 | test_make_relative("../foo", "/foo", "/bar", 0); | |
48 | test_make_relative("path/to/foo.c", "/path/to/foo.c", "/", 0); | |
49 | test_make_relative("../foo", "path/to/foo", "path/to/bar", 0); | |
50 | ||
51 | test_make_relative("/path/to/foo.c", "/path/to/foo.c", "d:/path/to", GIT_ENOTFOUND); | |
52 | test_make_relative("d:/path/to/foo.c", "d:/path/to/foo.c", "/path/to", GIT_ENOTFOUND); | |
c25aa7cd | 53 | |
0ee9f31c ET |
54 | test_make_relative("/path/to/foo.c", "/path/to/foo.c", "not-a-rooted-path", GIT_ENOTFOUND); |
55 | test_make_relative("not-a-rooted-path", "not-a-rooted-path", "/path/to", GIT_ENOTFOUND); | |
c25aa7cd | 56 | |
0ee9f31c ET |
57 | test_make_relative("/path", "/path", "pathtofoo", GIT_ENOTFOUND); |
58 | test_make_relative("path", "path", "pathtofoo", GIT_ENOTFOUND); | |
59 | } | |
a64119e3 ET |
60 | |
61 | void test_path_core__isvalid_standard(void) | |
62 | { | |
e579e0f7 MB |
63 | cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar", 0)); |
64 | cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar/file.txt", 0)); | |
65 | cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar/.file", 0)); | |
66 | } | |
67 | ||
68 | /* Ensure that `is_valid_str` only reads str->size bytes */ | |
69 | void test_path_core__isvalid_standard_str(void) | |
70 | { | |
71 | git_str str = GIT_STR_INIT_CONST("foo/bar//zap", 0); | |
72 | unsigned int flags = GIT_FS_PATH_REJECT_EMPTY_COMPONENT; | |
73 | ||
74 | str.size = 0; | |
75 | cl_assert_equal_b(false, git_fs_path_str_is_valid(&str, flags)); | |
76 | ||
77 | str.size = 3; | |
78 | cl_assert_equal_b(true, git_fs_path_str_is_valid(&str, flags)); | |
79 | ||
80 | str.size = 4; | |
81 | cl_assert_equal_b(false, git_fs_path_str_is_valid(&str, flags)); | |
82 | ||
83 | str.size = 5; | |
84 | cl_assert_equal_b(true, git_fs_path_str_is_valid(&str, flags)); | |
85 | ||
86 | str.size = 7; | |
87 | cl_assert_equal_b(true, git_fs_path_str_is_valid(&str, flags)); | |
88 | ||
89 | str.size = 8; | |
90 | cl_assert_equal_b(false, git_fs_path_str_is_valid(&str, flags)); | |
91 | ||
92 | str.size = strlen(str.ptr); | |
93 | cl_assert_equal_b(false, git_fs_path_str_is_valid(&str, flags)); | |
a64119e3 ET |
94 | } |
95 | ||
96 | void test_path_core__isvalid_empty_dir_component(void) | |
97 | { | |
e579e0f7 MB |
98 | unsigned int flags = GIT_FS_PATH_REJECT_EMPTY_COMPONENT; |
99 | ||
100 | /* empty component */ | |
101 | cl_assert_equal_b(true, git_fs_path_is_valid("foo//bar", 0)); | |
a64119e3 ET |
102 | |
103 | /* leading slash */ | |
e579e0f7 MB |
104 | cl_assert_equal_b(true, git_fs_path_is_valid("/", 0)); |
105 | cl_assert_equal_b(true, git_fs_path_is_valid("/foo", 0)); | |
106 | cl_assert_equal_b(true, git_fs_path_is_valid("/foo/bar", 0)); | |
a64119e3 ET |
107 | |
108 | /* trailing slash */ | |
e579e0f7 MB |
109 | cl_assert_equal_b(true, git_fs_path_is_valid("foo/", 0)); |
110 | cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar/", 0)); | |
a64119e3 | 111 | |
e579e0f7 MB |
112 | |
113 | /* empty component */ | |
114 | cl_assert_equal_b(false, git_fs_path_is_valid("foo//bar", flags)); | |
115 | ||
116 | /* leading slash */ | |
117 | cl_assert_equal_b(false, git_fs_path_is_valid("/", flags)); | |
118 | cl_assert_equal_b(false, git_fs_path_is_valid("/foo", flags)); | |
119 | cl_assert_equal_b(false, git_fs_path_is_valid("/foo/bar", flags)); | |
120 | ||
121 | /* trailing slash */ | |
122 | cl_assert_equal_b(false, git_fs_path_is_valid("foo/", flags)); | |
123 | cl_assert_equal_b(false, git_fs_path_is_valid("foo/bar/", flags)); | |
a64119e3 ET |
124 | } |
125 | ||
e579e0f7 | 126 | void test_path_core__isvalid_dot_and_dotdot(void) |
a64119e3 | 127 | { |
e579e0f7 MB |
128 | cl_assert_equal_b(true, git_fs_path_is_valid(".", 0)); |
129 | cl_assert_equal_b(true, git_fs_path_is_valid("./foo", 0)); | |
130 | cl_assert_equal_b(true, git_fs_path_is_valid("foo/.", 0)); | |
131 | cl_assert_equal_b(true, git_fs_path_is_valid("./foo", 0)); | |
132 | ||
133 | cl_assert_equal_b(true, git_fs_path_is_valid("..", 0)); | |
134 | cl_assert_equal_b(true, git_fs_path_is_valid("../foo", 0)); | |
135 | cl_assert_equal_b(true, git_fs_path_is_valid("foo/..", 0)); | |
136 | cl_assert_equal_b(true, git_fs_path_is_valid("../foo", 0)); | |
137 | ||
138 | cl_assert_equal_b(false, git_fs_path_is_valid(".", GIT_FS_PATH_REJECT_TRAVERSAL)); | |
139 | cl_assert_equal_b(false, git_fs_path_is_valid("./foo", GIT_FS_PATH_REJECT_TRAVERSAL)); | |
140 | cl_assert_equal_b(false, git_fs_path_is_valid("foo/.", GIT_FS_PATH_REJECT_TRAVERSAL)); | |
141 | cl_assert_equal_b(false, git_fs_path_is_valid("./foo", GIT_FS_PATH_REJECT_TRAVERSAL)); | |
142 | ||
143 | cl_assert_equal_b(false, git_fs_path_is_valid("..", GIT_FS_PATH_REJECT_TRAVERSAL)); | |
144 | cl_assert_equal_b(false, git_fs_path_is_valid("../foo", GIT_FS_PATH_REJECT_TRAVERSAL)); | |
145 | cl_assert_equal_b(false, git_fs_path_is_valid("foo/..", GIT_FS_PATH_REJECT_TRAVERSAL)); | |
146 | cl_assert_equal_b(false, git_fs_path_is_valid("../foo", GIT_FS_PATH_REJECT_TRAVERSAL)); | |
a64119e3 ET |
147 | } |
148 | ||
149 | void test_path_core__isvalid_backslash(void) | |
150 | { | |
e579e0f7 MB |
151 | cl_assert_equal_b(true, git_fs_path_is_valid("foo\\file.txt", 0)); |
152 | cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar\\file.txt", 0)); | |
153 | cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar\\", 0)); | |
a64119e3 | 154 | |
e579e0f7 MB |
155 | cl_assert_equal_b(false, git_fs_path_is_valid("foo\\file.txt", GIT_FS_PATH_REJECT_BACKSLASH)); |
156 | cl_assert_equal_b(false, git_fs_path_is_valid("foo/bar\\file.txt", GIT_FS_PATH_REJECT_BACKSLASH)); | |
157 | cl_assert_equal_b(false, git_fs_path_is_valid("foo/bar\\", GIT_FS_PATH_REJECT_BACKSLASH)); | |
a64119e3 ET |
158 | } |
159 | ||
160 | void test_path_core__isvalid_trailing_dot(void) | |
161 | { | |
e579e0f7 MB |
162 | cl_assert_equal_b(true, git_fs_path_is_valid("foo.", 0)); |
163 | cl_assert_equal_b(true, git_fs_path_is_valid("foo...", 0)); | |
164 | cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar.", 0)); | |
165 | cl_assert_equal_b(true, git_fs_path_is_valid("foo./bar", 0)); | |
166 | ||
167 | cl_assert_equal_b(false, git_fs_path_is_valid("foo.", GIT_FS_PATH_REJECT_TRAILING_DOT)); | |
168 | cl_assert_equal_b(false, git_fs_path_is_valid("foo...", GIT_FS_PATH_REJECT_TRAILING_DOT)); | |
169 | cl_assert_equal_b(false, git_fs_path_is_valid("foo/bar.", GIT_FS_PATH_REJECT_TRAILING_DOT)); | |
170 | cl_assert_equal_b(false, git_fs_path_is_valid("foo./bar", GIT_FS_PATH_REJECT_TRAILING_DOT)); | |
a64119e3 ET |
171 | } |
172 | ||
173 | void test_path_core__isvalid_trailing_space(void) | |
174 | { | |
e579e0f7 MB |
175 | cl_assert_equal_b(true, git_fs_path_is_valid("foo ", 0)); |
176 | cl_assert_equal_b(true, git_fs_path_is_valid("foo ", 0)); | |
177 | cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar ", 0)); | |
178 | cl_assert_equal_b(true, git_fs_path_is_valid(" ", 0)); | |
179 | cl_assert_equal_b(true, git_fs_path_is_valid("foo /bar", 0)); | |
180 | ||
181 | cl_assert_equal_b(false, git_fs_path_is_valid("foo ", GIT_FS_PATH_REJECT_TRAILING_SPACE)); | |
182 | cl_assert_equal_b(false, git_fs_path_is_valid("foo ", GIT_FS_PATH_REJECT_TRAILING_SPACE)); | |
183 | cl_assert_equal_b(false, git_fs_path_is_valid("foo/bar ", GIT_FS_PATH_REJECT_TRAILING_SPACE)); | |
184 | cl_assert_equal_b(false, git_fs_path_is_valid(" ", GIT_FS_PATH_REJECT_TRAILING_SPACE)); | |
185 | cl_assert_equal_b(false, git_fs_path_is_valid("foo /bar", GIT_FS_PATH_REJECT_TRAILING_SPACE)); | |
a64119e3 ET |
186 | } |
187 | ||
188 | void test_path_core__isvalid_trailing_colon(void) | |
189 | { | |
e579e0f7 MB |
190 | cl_assert_equal_b(true, git_fs_path_is_valid("foo:", 0)); |
191 | cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar:", 0)); | |
192 | cl_assert_equal_b(true, git_fs_path_is_valid(":", 0)); | |
193 | cl_assert_equal_b(true, git_fs_path_is_valid("foo:/bar", 0)); | |
194 | ||
195 | cl_assert_equal_b(false, git_fs_path_is_valid("foo:", GIT_FS_PATH_REJECT_TRAILING_COLON)); | |
196 | cl_assert_equal_b(false, git_fs_path_is_valid("foo/bar:", GIT_FS_PATH_REJECT_TRAILING_COLON)); | |
197 | cl_assert_equal_b(false, git_fs_path_is_valid(":", GIT_FS_PATH_REJECT_TRAILING_COLON)); | |
198 | cl_assert_equal_b(false, git_fs_path_is_valid("foo:/bar", GIT_FS_PATH_REJECT_TRAILING_COLON)); | |
a64119e3 ET |
199 | } |
200 | ||
201 | void test_path_core__isvalid_dos_paths(void) | |
202 | { | |
e579e0f7 MB |
203 | cl_assert_equal_b(true, git_fs_path_is_valid("aux", 0)); |
204 | cl_assert_equal_b(true, git_fs_path_is_valid("aux.", 0)); | |
205 | cl_assert_equal_b(true, git_fs_path_is_valid("aux:", 0)); | |
206 | cl_assert_equal_b(true, git_fs_path_is_valid("aux.asdf", 0)); | |
207 | cl_assert_equal_b(true, git_fs_path_is_valid("aux.asdf\\zippy", 0)); | |
208 | cl_assert_equal_b(true, git_fs_path_is_valid("aux:asdf\\foobar", 0)); | |
209 | cl_assert_equal_b(true, git_fs_path_is_valid("con", 0)); | |
210 | cl_assert_equal_b(true, git_fs_path_is_valid("prn", 0)); | |
211 | cl_assert_equal_b(true, git_fs_path_is_valid("nul", 0)); | |
212 | ||
213 | cl_assert_equal_b(false, git_fs_path_is_valid("aux", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
214 | cl_assert_equal_b(false, git_fs_path_is_valid("aux.", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
215 | cl_assert_equal_b(false, git_fs_path_is_valid("aux:", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
216 | cl_assert_equal_b(false, git_fs_path_is_valid("aux.asdf", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
217 | cl_assert_equal_b(false, git_fs_path_is_valid("aux.asdf\\zippy", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
218 | cl_assert_equal_b(false, git_fs_path_is_valid("aux:asdf\\foobar", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
219 | cl_assert_equal_b(false, git_fs_path_is_valid("con", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
220 | cl_assert_equal_b(false, git_fs_path_is_valid("prn", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
221 | cl_assert_equal_b(false, git_fs_path_is_valid("nul", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
222 | ||
223 | cl_assert_equal_b(true, git_fs_path_is_valid("aux1", 0)); | |
224 | cl_assert_equal_b(true, git_fs_path_is_valid("aux1", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
225 | cl_assert_equal_b(true, git_fs_path_is_valid("auxn", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
226 | cl_assert_equal_b(true, git_fs_path_is_valid("aux\\foo", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
a64119e3 ET |
227 | } |
228 | ||
229 | void test_path_core__isvalid_dos_paths_withnum(void) | |
230 | { | |
e579e0f7 MB |
231 | cl_assert_equal_b(true, git_fs_path_is_valid("com1", 0)); |
232 | cl_assert_equal_b(true, git_fs_path_is_valid("com1.", 0)); | |
233 | cl_assert_equal_b(true, git_fs_path_is_valid("com1:", 0)); | |
234 | cl_assert_equal_b(true, git_fs_path_is_valid("com1.asdf", 0)); | |
235 | cl_assert_equal_b(true, git_fs_path_is_valid("com1.asdf\\zippy", 0)); | |
236 | cl_assert_equal_b(true, git_fs_path_is_valid("com1:asdf\\foobar", 0)); | |
237 | cl_assert_equal_b(true, git_fs_path_is_valid("com1\\foo", 0)); | |
238 | cl_assert_equal_b(true, git_fs_path_is_valid("lpt1", 0)); | |
239 | ||
240 | cl_assert_equal_b(false, git_fs_path_is_valid("com1", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
241 | cl_assert_equal_b(false, git_fs_path_is_valid("com1.", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
242 | cl_assert_equal_b(false, git_fs_path_is_valid("com1:", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
243 | cl_assert_equal_b(false, git_fs_path_is_valid("com1.asdf", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
244 | cl_assert_equal_b(false, git_fs_path_is_valid("com1.asdf\\zippy", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
245 | cl_assert_equal_b(false, git_fs_path_is_valid("com1:asdf\\foobar", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
246 | cl_assert_equal_b(false, git_fs_path_is_valid("com1/foo", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
247 | cl_assert_equal_b(false, git_fs_path_is_valid("lpt1", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
248 | ||
249 | cl_assert_equal_b(true, git_fs_path_is_valid("com0", 0)); | |
250 | cl_assert_equal_b(true, git_fs_path_is_valid("com0", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
251 | cl_assert_equal_b(true, git_fs_path_is_valid("com10", 0)); | |
252 | cl_assert_equal_b(true, git_fs_path_is_valid("com10", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
253 | cl_assert_equal_b(true, git_fs_path_is_valid("comn", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
254 | cl_assert_equal_b(true, git_fs_path_is_valid("com1\\foo", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
255 | cl_assert_equal_b(true, git_fs_path_is_valid("lpt0", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
256 | cl_assert_equal_b(true, git_fs_path_is_valid("lpt10", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
257 | cl_assert_equal_b(true, git_fs_path_is_valid("lptn", GIT_FS_PATH_REJECT_DOS_PATHS)); | |
a64119e3 ET |
258 | } |
259 | ||
11d67b75 | 260 | void test_path_core__isvalid_nt_chars(void) |
a64119e3 | 261 | { |
e579e0f7 MB |
262 | cl_assert_equal_b(true, git_fs_path_is_valid("asdf\001foo", 0)); |
263 | cl_assert_equal_b(true, git_fs_path_is_valid("asdf\037bar", 0)); | |
264 | cl_assert_equal_b(true, git_fs_path_is_valid("asdf<bar", 0)); | |
265 | cl_assert_equal_b(true, git_fs_path_is_valid("asdf>foo", 0)); | |
266 | cl_assert_equal_b(true, git_fs_path_is_valid("asdf:foo", 0)); | |
267 | cl_assert_equal_b(true, git_fs_path_is_valid("asdf\"bar", 0)); | |
268 | cl_assert_equal_b(true, git_fs_path_is_valid("asdf|foo", 0)); | |
269 | cl_assert_equal_b(true, git_fs_path_is_valid("asdf?bar", 0)); | |
270 | cl_assert_equal_b(true, git_fs_path_is_valid("asdf*bar", 0)); | |
271 | ||
272 | cl_assert_equal_b(false, git_fs_path_is_valid("asdf\001foo", GIT_FS_PATH_REJECT_NT_CHARS)); | |
273 | cl_assert_equal_b(false, git_fs_path_is_valid("asdf\037bar", GIT_FS_PATH_REJECT_NT_CHARS)); | |
274 | cl_assert_equal_b(false, git_fs_path_is_valid("asdf<bar", GIT_FS_PATH_REJECT_NT_CHARS)); | |
275 | cl_assert_equal_b(false, git_fs_path_is_valid("asdf>foo", GIT_FS_PATH_REJECT_NT_CHARS)); | |
276 | cl_assert_equal_b(false, git_fs_path_is_valid("asdf:foo", GIT_FS_PATH_REJECT_NT_CHARS)); | |
277 | cl_assert_equal_b(false, git_fs_path_is_valid("asdf\"bar", GIT_FS_PATH_REJECT_NT_CHARS)); | |
278 | cl_assert_equal_b(false, git_fs_path_is_valid("asdf|foo", GIT_FS_PATH_REJECT_NT_CHARS)); | |
279 | cl_assert_equal_b(false, git_fs_path_is_valid("asdf?bar", GIT_FS_PATH_REJECT_NT_CHARS)); | |
280 | cl_assert_equal_b(false, git_fs_path_is_valid("asdf*bar", GIT_FS_PATH_REJECT_NT_CHARS)); | |
c25aa7cd PP |
281 | } |
282 | ||
283 | void test_path_core__validate_workdir(void) | |
284 | { | |
e579e0f7 MB |
285 | cl_must_pass(git_path_validate_length(NULL, "/foo/bar")); |
286 | cl_must_pass(git_path_validate_length(NULL, "C:\\Foo\\Bar")); | |
287 | cl_must_pass(git_path_validate_length(NULL, "\\\\?\\C:\\Foo\\Bar")); | |
288 | cl_must_pass(git_path_validate_length(NULL, "\\\\?\\C:\\Foo\\Bar")); | |
289 | cl_must_pass(git_path_validate_length(NULL, "\\\\?\\UNC\\server\\C$\\folder")); | |
c25aa7cd PP |
290 | |
291 | #ifdef GIT_WIN32 | |
292 | /* | |
e579e0f7 | 293 | * In the absence of a repo configuration, 259 character paths |
c25aa7cd PP |
294 | * succeed. >= 260 character paths fail. |
295 | */ | |
e579e0f7 MB |
296 | cl_must_pass(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\ok.txt")); |
297 | cl_must_pass(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\260.txt")); | |
298 | cl_must_fail(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\longer_than_260.txt")); | |
c25aa7cd PP |
299 | |
300 | /* count characters, not bytes */ | |
e579e0f7 MB |
301 | cl_must_pass(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\260.txt")); |
302 | cl_must_fail(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\long.txt")); | |
c25aa7cd | 303 | #else |
e579e0f7 MB |
304 | cl_must_pass(git_path_validate_length(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/ok.txt")); |
305 | cl_must_pass(git_path_validate_length(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/260.txt")); | |
306 | cl_must_pass(git_path_validate_length(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); | |
307 | cl_must_pass(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\260.txt")); | |
308 | cl_must_pass(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\long.txt")); | |
c25aa7cd PP |
309 | #endif |
310 | } | |
311 | ||
312 | void test_path_core__validate_workdir_with_core_longpath(void) | |
313 | { | |
314 | #ifdef GIT_WIN32 | |
315 | git_repository *repo; | |
316 | git_config *config; | |
317 | ||
318 | repo = cl_git_sandbox_init("empty_bare.git"); | |
319 | ||
320 | cl_git_pass(git_repository_open(&repo, "empty_bare.git")); | |
321 | cl_git_pass(git_repository_config(&config, repo)); | |
322 | ||
323 | /* fail by default */ | |
e579e0f7 | 324 | cl_must_fail(git_path_validate_length(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); |
c25aa7cd PP |
325 | |
326 | /* set core.longpaths explicitly on */ | |
327 | cl_git_pass(git_config_set_bool(config, "core.longpaths", 1)); | |
e579e0f7 | 328 | cl_must_pass(git_path_validate_length(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); |
c25aa7cd PP |
329 | |
330 | /* set core.longpaths explicitly off */ | |
331 | cl_git_pass(git_config_set_bool(config, "core.longpaths", 0)); | |
e579e0f7 | 332 | cl_must_fail(git_path_validate_length(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); |
c25aa7cd PP |
333 | |
334 | git_config_free(config); | |
335 | git_repository_free(repo); | |
336 | #endif | |
11d67b75 | 337 | } |
1fbfcdfc ET |
338 | |
339 | static void test_join_unrooted( | |
340 | const char *expected_result, | |
341 | ssize_t expected_rootlen, | |
342 | const char *path, | |
343 | const char *base) | |
344 | { | |
e579e0f7 | 345 | git_str result = GIT_STR_INIT; |
1fbfcdfc ET |
346 | ssize_t root_at; |
347 | ||
e579e0f7 | 348 | cl_git_pass(git_fs_path_join_unrooted(&result, path, base, &root_at)); |
1fbfcdfc ET |
349 | cl_assert_equal_s(expected_result, result.ptr); |
350 | cl_assert_equal_i(expected_rootlen, root_at); | |
351 | ||
e579e0f7 | 352 | git_str_dispose(&result); |
1fbfcdfc ET |
353 | } |
354 | ||
355 | void test_path_core__join_unrooted(void) | |
356 | { | |
e579e0f7 | 357 | git_str out = GIT_STR_INIT; |
1fbfcdfc ET |
358 | |
359 | test_join_unrooted("foo", 0, "foo", NULL); | |
360 | test_join_unrooted("foo/bar", 0, "foo/bar", NULL); | |
361 | ||
362 | /* Relative paths have base prepended */ | |
363 | test_join_unrooted("/foo/bar", 4, "bar", "/foo"); | |
364 | test_join_unrooted("/foo/bar/foobar", 4, "bar/foobar", "/foo"); | |
365 | test_join_unrooted("c:/foo/bar/foobar", 6, "bar/foobar", "c:/foo"); | |
366 | test_join_unrooted("c:/foo/bar/foobar", 10, "foobar", "c:/foo/bar"); | |
367 | ||
368 | /* Absolute paths are not prepended with base */ | |
369 | test_join_unrooted("/foo", 0, "/foo", "/asdf"); | |
370 | test_join_unrooted("/foo/bar", 0, "/foo/bar", "/asdf"); | |
371 | ||
372 | /* Drive letter is given as root length on Windows */ | |
373 | test_join_unrooted("c:/foo", 2, "c:/foo", "c:/asdf"); | |
374 | test_join_unrooted("c:/foo/bar", 2, "c:/foo/bar", "c:/asdf"); | |
375 | ||
22a2d3d5 UG |
376 | #ifdef GIT_WIN32 |
377 | /* Paths starting with '\\' are absolute */ | |
378 | test_join_unrooted("\\bar", 0, "\\bar", "c:/foo/"); | |
379 | test_join_unrooted("\\\\network\\bar", 9, "\\\\network\\bar", "c:/foo/"); | |
380 | #else | |
381 | /* Paths starting with '\\' are not absolute on non-Windows systems */ | |
382 | test_join_unrooted("/foo/\\bar", 4, "\\bar", "/foo"); | |
383 | test_join_unrooted("c:/foo/\\bar", 7, "\\bar", "c:/foo/"); | |
384 | #endif | |
385 | ||
1fbfcdfc ET |
386 | /* Base is returned when it's provided and is the prefix */ |
387 | test_join_unrooted("c:/foo/bar/foobar", 6, "c:/foo/bar/foobar", "c:/foo"); | |
388 | test_join_unrooted("c:/foo/bar/foobar", 10, "c:/foo/bar/foobar", "c:/foo/bar"); | |
389 | ||
390 | /* Trailing slash in the base is ignored */ | |
391 | test_join_unrooted("c:/foo/bar/foobar", 6, "c:/foo/bar/foobar", "c:/foo/"); | |
392 | ||
e579e0f7 | 393 | git_str_dispose(&out); |
1fbfcdfc | 394 | } |
b6832cbf UG |
395 | |
396 | void test_path_core__join_unrooted_respects_funny_windows_roots(void) | |
397 | { | |
398 | test_join_unrooted("💩:/foo/bar/foobar", 9, "bar/foobar", "💩:/foo"); | |
399 | test_join_unrooted("💩:/foo/bar/foobar", 13, "foobar", "💩:/foo/bar"); | |
400 | test_join_unrooted("💩:/foo", 5, "💩:/foo", "💩:/asdf"); | |
401 | test_join_unrooted("💩:/foo/bar", 5, "💩:/foo/bar", "💩:/asdf"); | |
402 | test_join_unrooted("💩:/foo/bar/foobar", 9, "💩:/foo/bar/foobar", "💩:/foo"); | |
403 | test_join_unrooted("💩:/foo/bar/foobar", 13, "💩:/foo/bar/foobar", "💩:/foo/bar"); | |
404 | test_join_unrooted("💩:/foo/bar/foobar", 9, "💩:/foo/bar/foobar", "💩:/foo/"); | |
405 | } |