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>

Michael Haggerty committed Aug 4, 2011 at 06:36 UTC c0b13b21b8daa4bfb222e9c4d335c8b340c511a0
2 files changed +7 -1
attr.c
+1 -1
@@ -53,7 +53,7 @@ static int invalid_attr_name(const char *name, int namelen)
53 * Attribute name cannot begin with '-' and must consist of
54 * characters from [-A-Za-z0-9_.].
55 */
56 - if (*name == '-')
56 + if (namelen <= 0 || *name == '-')
57 return -1;
58 while (namelen--) {
59 char ch = *name++;
t/t0003-attributes.sh
+6
@@ -42,6 +42,12 @@ test_expect_success 'setup' '
42
43 '
44
45 +test_expect_success 'command line checks' '
46 +
47 + test_must_fail git check-attr "" -- f
48 +
49 +'
50 +
51 test_expect_success 'attribute test' '
52
53 attr_check f f &&