mirror of
https://github.com/libgit2/libgit2.git
synced 2026-01-25 02:56:17 +00:00
str: allow escaping with prefix and suffix
Allow `git_str_puts_escaped` to take an escaping prefix and an escaping suffix; this allows for more options, including the ability to better support escaping executed paths.
This commit is contained in:
@@ -691,17 +691,33 @@ void test_gitstr__puts_escaped(void)
|
||||
git_str a = GIT_STR_INIT;
|
||||
|
||||
git_str_clear(&a);
|
||||
cl_git_pass(git_str_puts_escaped(&a, "this is a test", "", ""));
|
||||
cl_git_pass(git_str_puts_escaped(&a, "this is a test", "", "", ""));
|
||||
cl_assert_equal_s("this is a test", a.ptr);
|
||||
|
||||
git_str_clear(&a);
|
||||
cl_git_pass(git_str_puts_escaped(&a, "this is a test", "t", "\\"));
|
||||
cl_git_pass(git_str_puts_escaped(&a, "this is a test", "", NULL, NULL));
|
||||
cl_assert_equal_s("this is a test", a.ptr);
|
||||
|
||||
git_str_clear(&a);
|
||||
cl_git_pass(git_str_puts_escaped(&a, "this is a test", "t", "\\", ""));
|
||||
cl_assert_equal_s("\\this is a \\tes\\t", a.ptr);
|
||||
|
||||
git_str_clear(&a);
|
||||
cl_git_pass(git_str_puts_escaped(&a, "this is a test", "i ", "__"));
|
||||
cl_git_pass(git_str_puts_escaped(&a, "this is a test", "t", "\\", NULL));
|
||||
cl_assert_equal_s("\\this is a \\tes\\t", a.ptr);
|
||||
|
||||
git_str_clear(&a);
|
||||
cl_git_pass(git_str_puts_escaped(&a, "this is a test", "i ", "__", NULL));
|
||||
cl_assert_equal_s("th__is__ __is__ a__ test", a.ptr);
|
||||
|
||||
git_str_clear(&a);
|
||||
cl_git_pass(git_str_puts_escaped(&a, "this is a test", "i ", "__", "!!"));
|
||||
cl_assert_equal_s("th__i!!s__ !!__i!!s__ !!a__ !!test", a.ptr);
|
||||
|
||||
git_str_clear(&a);
|
||||
cl_git_pass(git_str_puts_escaped(&a, "this' is' an' escape! ", "'!", "'\\", "'"));
|
||||
cl_assert_equal_s("this'\\'' is'\\'' an'\\'' escape'\\!' ", a.ptr);
|
||||
|
||||
git_str_clear(&a);
|
||||
cl_git_pass(git_str_puts_escape_regex(&a, "^match\\s*[A-Z]+.*"));
|
||||
cl_assert_equal_s("\\^match\\\\s\\*\\[A-Z\\]\\+\\.\\*", a.ptr);
|
||||
|
||||
Reference in New Issue
Block a user