Skip to content

Commit c0b13b2

Browse files
mhaggergitster
authored andcommitted
Disallow the empty string as an attribute name
Previously, it was possible to have a line like "file.txt =foo" in a .gitattribute file, after which an invocation like "git check-attr '' -- file.txt" would succeed. This patch disallows both constructs. Please note that any existing .gitattributes file that tries to set an empty attribute will now trigger the error message "error: : not a valid attribute name" whereas previously the nonsense was allowed through. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent d42453a commit c0b13b2

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

attr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static int invalid_attr_name(const char *name, int namelen)
5353
* Attribute name cannot begin with '-' and must consist of
5454
* characters from [-A-Za-z0-9_.].
5555
*/
56-
if (*name == '-')
56+
if (namelen <= 0 || *name == '-')
5757
return -1;
5858
while (namelen--) {
5959
char ch = *name++;

t/t0003-attributes.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ test_expect_success 'setup' '
4242
4343
'
4444

45+
test_expect_success 'command line checks' '
46+
47+
test_must_fail git check-attr "" -- f
48+
49+
'
50+
4551
test_expect_success 'attribute test' '
4652
4753
attr_check f f &&

0 commit comments

Comments
 (0)