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>
This commit is contained in:
parent
d42453ab1a
commit
c0b13b21b8
2
attr.c
2
attr.c
@ -53,7 +53,7 @@ static int invalid_attr_name(const char *name, int namelen)
|
|||||||
* Attribute name cannot begin with '-' and must consist of
|
* Attribute name cannot begin with '-' and must consist of
|
||||||
* characters from [-A-Za-z0-9_.].
|
* characters from [-A-Za-z0-9_.].
|
||||||
*/
|
*/
|
||||||
if (*name == '-')
|
if (namelen <= 0 || *name == '-')
|
||||||
return -1;
|
return -1;
|
||||||
while (namelen--) {
|
while (namelen--) {
|
||||||
char ch = *name++;
|
char ch = *name++;
|
||||||
|
@ -42,6 +42,12 @@ test_expect_success 'setup' '
|
|||||||
|
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'command line checks' '
|
||||||
|
|
||||||
|
test_must_fail git check-attr "" -- f
|
||||||
|
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'attribute test' '
|
test_expect_success 'attribute test' '
|
||||||
|
|
||||||
attr_check f f &&
|
attr_check f f &&
|
||||||
|
Loading…
Reference in New Issue
Block a user