Skip to content

Commit be5acb3

Browse files
committed
Merge branch 'mh/check-ref-format-print-normalize' into maint
* mh/check-ref-format-print-normalize: Forbid DEL characters in reference names check-ref-format --print: Normalize refnames that start with slashes
2 parents 503359f + f3738c1 commit be5acb3

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

builtin/check-ref-format.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ static const char builtin_check_ref_format_usage[] =
1212
" or: git check-ref-format --branch <branchname-shorthand>";
1313

1414
/*
15-
* Replace each run of adjacent slashes in src with a single slash,
16-
* and write the result to dst.
15+
* Remove leading slashes and replace each run of adjacent slashes in
16+
* src with a single slash, and write the result to dst.
1717
*
1818
* This function is similar to normalize_path_copy(), but stripped down
1919
* to meet check_ref_format's simpler needs.
2020
*/
2121
static void collapse_slashes(char *dst, const char *src)
2222
{
2323
char ch;
24-
char prev = '\0';
24+
char prev = '/';
2525

2626
while ((ch = *src++) != '\0') {
2727
if (prev == '/' && ch == prev)

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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ invalid_ref 'foo'
1818
valid_ref 'foo/bar/baz'
1919
valid_ref 'refs///heads/foo'
2020
invalid_ref 'heads/foo/'
21+
valid_ref '/heads/foo'
22+
valid_ref '///heads/foo'
23+
invalid_ref '/foo'
2124
invalid_ref './foo'
2225
invalid_ref '.refs/foo'
2326
invalid_ref 'heads/foo..bar'
@@ -27,6 +30,9 @@ invalid_ref 'heads/foo.lock'
2730
valid_ref 'heads/foo@bar'
2831
invalid_ref 'heads/v@{ation'
2932
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')"
3036

3137
test_expect_success "check-ref-format --branch @{-1}" '
3238
T=$(git write-tree) &&
@@ -70,7 +76,10 @@ invalid_ref_normalized() {
7076

7177
valid_ref_normalized 'heads/foo' 'heads/foo'
7278
valid_ref_normalized 'refs///heads/foo' 'refs/heads/foo'
79+
valid_ref_normalized '/heads/foo' 'heads/foo'
80+
valid_ref_normalized '///heads/foo' 'heads/foo'
7381
invalid_ref_normalized 'foo'
82+
invalid_ref_normalized '/foo'
7483
invalid_ref_normalized 'heads/foo/../bar'
7584
invalid_ref_normalized 'heads/./foo'
7685
invalid_ref_normalized 'heads\foo'

0 commit comments

Comments
 (0)