ident: reject all-crud ident name
An ident name consisting of only "crud" characters (like whitespace or punctuation) is effectively the same as an empty one, because our strbuf_addstr_without_crud() will remove those characters. We reject an empty name when formatting a strict ident, but don't notice an all-crud one because our check happens before the crud-removal step. We could skip past the crud before checking for an empty name, but let's make it a separate code path, for two reasons. One is that we can give a more specific error message. And two is that unlike a blank name, we probably don't want to kick in the fallback-to-username behavior. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
862e80a413
commit
13b9a24e58
11
ident.c
11
ident.c
|
@ -203,6 +203,15 @@ static int crud(unsigned char c)
|
||||||
c == '\'';
|
c == '\'';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int has_non_crud(const char *str)
|
||||||
|
{
|
||||||
|
for (; *str; str++) {
|
||||||
|
if (!crud(*str))
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copy over a string to the destination, but avoid special
|
* Copy over a string to the destination, but avoid special
|
||||||
* characters ('\n', '<' and '>') and remove crud at the end
|
* characters ('\n', '<' and '>') and remove crud at the end
|
||||||
|
@ -389,6 +398,8 @@ const char *fmt_ident(const char *name, const char *email,
|
||||||
pw = xgetpwuid_self(NULL);
|
pw = xgetpwuid_self(NULL);
|
||||||
name = pw->pw_name;
|
name = pw->pw_name;
|
||||||
}
|
}
|
||||||
|
if (strict && !has_non_crud(name))
|
||||||
|
die(_("name consists only of disallowed characters: %s"), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
strbuf_reset(&ident);
|
strbuf_reset(&ident);
|
||||||
|
|
|
@ -17,4 +17,9 @@ test_expect_success 'empty name and missing email' '
|
||||||
)
|
)
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'commit rejects all-crud name' '
|
||||||
|
test_must_fail env GIT_AUTHOR_NAME=" .;<>" \
|
||||||
|
git commit --allow-empty -m foo
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
Loading…
Reference in New Issue