Skip to content

Commit f3738c1

Browse files
mhaggergitster
authored andcommitted
Forbid DEL characters in reference names
DEL is an ASCII control character and therefore should not be permitted in reference names. Add tests for this and other unusual characters. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 2f633f4 commit f3738c1

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

refs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ int for_each_rawref(each_ref_fn fn, void *cb_data)
837837

838838
static inline int bad_ref_char(int ch)
839839
{
840-
if (((unsigned) ch) <= ' ' ||
840+
if (((unsigned) ch) <= ' ' || ch == 0x7f ||
841841
ch == '~' || ch == '^' || ch == ':' || ch == '\\')
842842
return 1;
843843
/* 2.13 Pattern Matching Notation */

t/t1402-check-ref-format.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ invalid_ref 'heads/foo.lock'
3030
valid_ref 'heads/foo@bar'
3131
invalid_ref 'heads/v@{ation'
3232
invalid_ref 'heads/foo\bar'
33+
invalid_ref "$(printf 'heads/foo\t')"
34+
invalid_ref "$(printf 'heads/foo\177')"
35+
valid_ref "$(printf 'heads/fu\303\237')"
3336

3437
test_expect_success "check-ref-format --branch @{-1}" '
3538
T=$(git write-tree) &&

0 commit comments

Comments
 (0)