path: introduce `git_path_str_is_valid` Add a `git_str` based validity check; the existing `git_path_is_valid` defers to it.
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
diff --git a/src/fs_path.c b/src/fs_path.c
index de3b039..9079c30 100644
--- a/src/fs_path.c
+++ b/src/fs_path.c
@@ -1647,7 +1647,7 @@ GIT_INLINE(bool) validate_length(
}
#endif
-bool git_fs_path_is_valid_str_ext(
+bool git_fs_path_str_is_valid_ext(
const git_str *path,
unsigned int flags,
bool (*validate_char_cb)(char ch, void *payload),
diff --git a/src/fs_path.h b/src/fs_path.h
index 40b4342..947c4ae 100644
--- a/src/fs_path.h
+++ b/src/fs_path.h
@@ -628,7 +628,7 @@ extern int git_fs_path_from_url_or_path(git_str *local_path_out, const char *url
* Validate a filesystem path; with custom callbacks per-character and
* per-path component.
*/
-extern bool git_fs_path_is_valid_str_ext(
+extern bool git_fs_path_str_is_valid_ext(
const git_str *path,
unsigned int flags,
bool (*validate_char_cb)(char ch, void *payload),
@@ -645,7 +645,7 @@ GIT_INLINE(bool) git_fs_path_is_valid_ext(
void *payload)
{
const git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX);
- return git_fs_path_is_valid_str_ext(
+ return git_fs_path_str_is_valid_ext(
&str,
flags,
validate_char_cb,
@@ -666,15 +666,15 @@ GIT_INLINE(bool) git_fs_path_is_valid(
unsigned int flags)
{
const git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX);
- return git_fs_path_is_valid_str_ext(&str, flags, NULL, NULL, NULL, NULL);
+ return git_fs_path_str_is_valid_ext(&str, flags, NULL, NULL, NULL, NULL);
}
/** Validate a filesystem path in a `git_str`. */
-GIT_INLINE(bool) git_fs_path_is_valid_str(
+GIT_INLINE(bool) git_fs_path_str_is_valid(
const git_str *path,
unsigned int flags)
{
- return git_fs_path_is_valid_str_ext(path, flags, NULL, NULL, NULL, NULL);
+ return git_fs_path_str_is_valid_ext(path, flags, NULL, NULL, NULL, NULL);
}
/**
diff --git a/src/path.c b/src/path.c
index a6b396f..933444d 100644
--- a/src/path.c
+++ b/src/path.c
@@ -285,9 +285,9 @@ GIT_INLINE(unsigned int) dotgit_flags(
return flags;
}
-bool git_path_is_valid(
+bool git_path_str_is_valid(
git_repository *repo,
- const char *path,
+ const git_str *path,
uint16_t file_mode,
unsigned int flags)
{
@@ -301,7 +301,7 @@ bool git_path_is_valid(
data.file_mode = file_mode;
data.flags = flags;
- return git_fs_path_is_valid_ext(path, flags, NULL, validate_repo_component, NULL, &data);
+ return git_fs_path_str_is_valid_ext(path, flags, NULL, validate_repo_component, NULL, &data);
}
static const struct {
diff --git a/src/path.h b/src/path.h
index f874a16..f2ac848 100644
--- a/src/path.h
+++ b/src/path.h
@@ -25,10 +25,20 @@
#define GIT_PATH_REJECT_INDEX_DEFAULTS \
GIT_FS_PATH_REJECT_TRAVERSAL | GIT_PATH_REJECT_DOT_GIT
-extern bool git_path_is_valid(
+extern bool git_path_str_is_valid(
git_repository *repo,
- const char *path,
+ const git_str *path,
uint16_t file_mode,
unsigned int flags);
+GIT_INLINE(bool) git_path_is_valid(
+ git_repository *repo,
+ const char *path,
+ uint16_t file_mode,
+ unsigned int flags)
+{
+ git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX);
+ return git_path_str_is_valid(repo, &str, file_mode, flags);
+}
+
#endif
diff --git a/tests/path/core.c b/tests/path/core.c
index ccb328b..eb6e5b8 100644
--- a/tests/path/core.c
+++ b/tests/path/core.c
@@ -71,25 +71,25 @@ void test_path_core__isvalid_standard_str(void)
unsigned int flags = GIT_FS_PATH_REJECT_EMPTY_COMPONENT;
str.size = 0;
- cl_assert_equal_b(false, git_fs_path_is_valid_str(&str, flags));
+ cl_assert_equal_b(false, git_fs_path_str_is_valid(&str, flags));
str.size = 3;
- cl_assert_equal_b(true, git_fs_path_is_valid_str(&str, flags));
+ cl_assert_equal_b(true, git_fs_path_str_is_valid(&str, flags));
str.size = 4;
- cl_assert_equal_b(false, git_fs_path_is_valid_str(&str, flags));
+ cl_assert_equal_b(false, git_fs_path_str_is_valid(&str, flags));
str.size = 5;
- cl_assert_equal_b(true, git_fs_path_is_valid_str(&str, flags));
+ cl_assert_equal_b(true, git_fs_path_str_is_valid(&str, flags));
str.size = 7;
- cl_assert_equal_b(true, git_fs_path_is_valid_str(&str, flags));
+ cl_assert_equal_b(true, git_fs_path_str_is_valid(&str, flags));
str.size = 8;
- cl_assert_equal_b(false, git_fs_path_is_valid_str(&str, flags));
+ cl_assert_equal_b(false, git_fs_path_str_is_valid(&str, flags));
str.size = strlen(str.ptr);
- cl_assert_equal_b(false, git_fs_path_is_valid_str(&str, flags));
+ cl_assert_equal_b(false, git_fs_path_str_is_valid(&str, flags));
}
void test_path_core__isvalid_empty_dir_component(void)