Skip to content

Commit 315a43b

Browse files
committed
path: introduce git_path_str_is_valid
Add a `git_str` based validity check; the existing `git_path_is_valid` defers to it.
1 parent ebacd24 commit 315a43b

File tree

5 files changed

+28
-18
lines changed

5 files changed

+28
-18
lines changed

src/fs_path.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1647,7 +1647,7 @@ GIT_INLINE(bool) validate_length(
16471647
}
16481648
#endif
16491649

1650-
bool git_fs_path_is_valid_str_ext(
1650+
bool git_fs_path_str_is_valid_ext(
16511651
const git_str *path,
16521652
unsigned int flags,
16531653
bool (*validate_char_cb)(char ch, void *payload),

src/fs_path.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ extern int git_fs_path_from_url_or_path(git_str *local_path_out, const char *url
628628
* Validate a filesystem path; with custom callbacks per-character and
629629
* per-path component.
630630
*/
631-
extern bool git_fs_path_is_valid_str_ext(
631+
extern bool git_fs_path_str_is_valid_ext(
632632
const git_str *path,
633633
unsigned int flags,
634634
bool (*validate_char_cb)(char ch, void *payload),
@@ -645,7 +645,7 @@ GIT_INLINE(bool) git_fs_path_is_valid_ext(
645645
void *payload)
646646
{
647647
const git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX);
648-
return git_fs_path_is_valid_str_ext(
648+
return git_fs_path_str_is_valid_ext(
649649
&str,
650650
flags,
651651
validate_char_cb,
@@ -666,15 +666,15 @@ GIT_INLINE(bool) git_fs_path_is_valid(
666666
unsigned int flags)
667667
{
668668
const git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX);
669-
return git_fs_path_is_valid_str_ext(&str, flags, NULL, NULL, NULL, NULL);
669+
return git_fs_path_str_is_valid_ext(&str, flags, NULL, NULL, NULL, NULL);
670670
}
671671

672672
/** Validate a filesystem path in a `git_str`. */
673-
GIT_INLINE(bool) git_fs_path_is_valid_str(
673+
GIT_INLINE(bool) git_fs_path_str_is_valid(
674674
const git_str *path,
675675
unsigned int flags)
676676
{
677-
return git_fs_path_is_valid_str_ext(path, flags, NULL, NULL, NULL, NULL);
677+
return git_fs_path_str_is_valid_ext(path, flags, NULL, NULL, NULL, NULL);
678678
}
679679

680680
/**

src/path.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,9 @@ GIT_INLINE(unsigned int) dotgit_flags(
285285
return flags;
286286
}
287287

288-
bool git_path_is_valid(
288+
bool git_path_str_is_valid(
289289
git_repository *repo,
290-
const char *path,
290+
const git_str *path,
291291
uint16_t file_mode,
292292
unsigned int flags)
293293
{
@@ -301,7 +301,7 @@ bool git_path_is_valid(
301301
data.file_mode = file_mode;
302302
data.flags = flags;
303303

304-
return git_fs_path_is_valid_ext(path, flags, NULL, validate_repo_component, NULL, &data);
304+
return git_fs_path_str_is_valid_ext(path, flags, NULL, validate_repo_component, NULL, &data);
305305
}
306306

307307
static const struct {

src/path.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,20 @@
2525
#define GIT_PATH_REJECT_INDEX_DEFAULTS \
2626
GIT_FS_PATH_REJECT_TRAVERSAL | GIT_PATH_REJECT_DOT_GIT
2727

28-
extern bool git_path_is_valid(
28+
extern bool git_path_str_is_valid(
2929
git_repository *repo,
30-
const char *path,
30+
const git_str *path,
3131
uint16_t file_mode,
3232
unsigned int flags);
3333

34+
GIT_INLINE(bool) git_path_is_valid(
35+
git_repository *repo,
36+
const char *path,
37+
uint16_t file_mode,
38+
unsigned int flags)
39+
{
40+
git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX);
41+
return git_path_str_is_valid(repo, &str, file_mode, flags);
42+
}
43+
3444
#endif

tests/path/core.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,25 @@ void test_path_core__isvalid_standard_str(void)
7171
unsigned int flags = GIT_FS_PATH_REJECT_EMPTY_COMPONENT;
7272

7373
str.size = 0;
74-
cl_assert_equal_b(false, git_fs_path_is_valid_str(&str, flags));
74+
cl_assert_equal_b(false, git_fs_path_str_is_valid(&str, flags));
7575

7676
str.size = 3;
77-
cl_assert_equal_b(true, git_fs_path_is_valid_str(&str, flags));
77+
cl_assert_equal_b(true, git_fs_path_str_is_valid(&str, flags));
7878

7979
str.size = 4;
80-
cl_assert_equal_b(false, git_fs_path_is_valid_str(&str, flags));
80+
cl_assert_equal_b(false, git_fs_path_str_is_valid(&str, flags));
8181

8282
str.size = 5;
83-
cl_assert_equal_b(true, git_fs_path_is_valid_str(&str, flags));
83+
cl_assert_equal_b(true, git_fs_path_str_is_valid(&str, flags));
8484

8585
str.size = 7;
86-
cl_assert_equal_b(true, git_fs_path_is_valid_str(&str, flags));
86+
cl_assert_equal_b(true, git_fs_path_str_is_valid(&str, flags));
8787

8888
str.size = 8;
89-
cl_assert_equal_b(false, git_fs_path_is_valid_str(&str, flags));
89+
cl_assert_equal_b(false, git_fs_path_str_is_valid(&str, flags));
9090

9191
str.size = strlen(str.ptr);
92-
cl_assert_equal_b(false, git_fs_path_is_valid_str(&str, flags));
92+
cl_assert_equal_b(false, git_fs_path_str_is_valid(&str, flags));
9393
}
9494

9595
void test_path_core__isvalid_empty_dir_component(void)

0 commit comments

Comments
 (0)