summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-11-01 17:37:06 -0400
committerEdward Thomson <ethomson@edwardthomson.com>2021-11-09 15:17:18 +0000
commit315a43b2f16fab679126f519a5dce1c9e1e335af (patch)
treebf233f04c88a8eabcf731d4719d9f8fd23491f77
parentebacd24c6039c992ef9122a0d6f7de0ca4ba3bd1 (diff)
downloadlibgit2-315a43b2f16fab679126f519a5dce1c9e1e335af.tar.gz
path: introduce `git_path_str_is_valid`
Add a `git_str` based validity check; the existing `git_path_is_valid` defers to it.
-rw-r--r--src/fs_path.c2
-rw-r--r--src/fs_path.h10
-rw-r--r--src/path.c6
-rw-r--r--src/path.h14
-rw-r--r--tests/path/core.c14
5 files changed, 28 insertions, 18 deletions
diff --git a/src/fs_path.c b/src/fs_path.c
index de3b03957..9079c30c9 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 40b4342f1..947c4ae86 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 a6b396f6d..933444de2 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 f874a16be..f2ac8484b 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 ccb328b10..eb6e5b851 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)