refspec: Detect DEL character in is_valid_name

Prior to this patch the code correctly barfed on
control characters with values lower than \040 (space),
but failed to account for DEL.

This patch fixes the behavior to be consistent with git [1]:

> They cannot have ASCII control characters (i.e. bytes whose values are
> lower than \040, or \177 DEL)

[1]: https://git-scm.com/docs/git-check-ref-format#_description
This commit is contained in:
Sergei Zimmerman
2025-08-13 12:13:50 +00:00
parent 58d9363f02
commit aaef091960
2 changed files with 2 additions and 1 deletions

View File

@@ -819,7 +819,7 @@ int git_reference_list(
static int is_valid_ref_char(char ch)
{
if ((unsigned) ch <= ' ')
if ((unsigned) ch <= ' ' || ch == '\177') /* ASCII control characters */
return 0;
switch (ch) {

View File

@@ -21,6 +21,7 @@ void test_refs_isvalidname__can_detect_invalid_formats(void)
cl_assert_equal_i(false, is_valid_name("/"));
cl_assert_equal_i(false, is_valid_name("//"));
cl_assert_equal_i(false, is_valid_name(""));
cl_assert_equal_i(false, is_valid_name("refs/heads/\177"));
cl_assert_equal_i(false, is_valid_name("refs/heads/sub.lock/webmatrix"));
}