Commit 315a43b2 by Edward Thomson

path: introduce `git_path_str_is_valid`

Add a `git_str` based validity check; the existing `git_path_is_valid`
defers to it.
parent ebacd24c
......@@ -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),
......
......@@ -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);
}
/**
......
......@@ -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 {
......
......@@ -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
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment