mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-29 20:42:23 +00:00
signature: Strip crud just like Git does
This commit is contained in:
parent
4280fabb9f
commit
307c4a2b6d
@ -34,13 +34,27 @@ static bool contains_angle_brackets(const char *input)
|
|||||||
return strchr(input, '<') != NULL || strchr(input, '>') != NULL;
|
return strchr(input, '<') != NULL || strchr(input, '>') != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool is_crud(unsigned char c)
|
||||||
|
{
|
||||||
|
return c <= 32 ||
|
||||||
|
c == '.' ||
|
||||||
|
c == ',' ||
|
||||||
|
c == ':' ||
|
||||||
|
c == ';' ||
|
||||||
|
c == '<' ||
|
||||||
|
c == '>' ||
|
||||||
|
c == '"' ||
|
||||||
|
c == '\\' ||
|
||||||
|
c == '\'';
|
||||||
|
}
|
||||||
|
|
||||||
static char *extract_trimmed(const char *ptr, size_t len)
|
static char *extract_trimmed(const char *ptr, size_t len)
|
||||||
{
|
{
|
||||||
while (len && git__isspace(ptr[0])) {
|
while (len && is_crud((unsigned char)ptr[0])) {
|
||||||
ptr++; len--;
|
ptr++; len--;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (len && git__isspace(ptr[len - 1])) {
|
while (len && is_crud((unsigned char)ptr[len - 1])) {
|
||||||
len--;
|
len--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,13 @@ void test_commit_signature__leading_and_trailing_spaces_are_trimmed(void)
|
|||||||
assert_name_and_email("nulltoken", "emeric.fermas@gmail.com", " \t nulltoken \n", " \n emeric.fermas@gmail.com \n");
|
assert_name_and_email("nulltoken", "emeric.fermas@gmail.com", " \t nulltoken \n", " \n emeric.fermas@gmail.com \n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_commit_signature__leading_and_trailing_crud_is_trimmed(void)
|
||||||
|
{
|
||||||
|
assert_name_and_email("nulltoken", "emeric.fermas@gmail.com", "\"nulltoken\"", "\"emeric.fermas@gmail.com\"");
|
||||||
|
assert_name_and_email("nulltoken w", "emeric.fermas@gmail.com", "nulltoken w.", "emeric.fermas@gmail.com");
|
||||||
|
assert_name_and_email("nulltoken \xe2\x98\xba", "emeric.fermas@gmail.com", "nulltoken \xe2\x98\xba", "emeric.fermas@gmail.com");
|
||||||
|
}
|
||||||
|
|
||||||
void test_commit_signature__angle_brackets_in_names_are_not_supported(void)
|
void test_commit_signature__angle_brackets_in_names_are_not_supported(void)
|
||||||
{
|
{
|
||||||
cl_git_fail(try_build_signature("<Phil Haack", "phil@haack", 1234567890, 60));
|
cl_git_fail(try_build_signature("<Phil Haack", "phil@haack", 1234567890, 60));
|
||||||
|
@ -38,7 +38,7 @@ void test_revwalk_signatureparsing__do_not_choke_when_name_contains_angle_bracke
|
|||||||
|
|
||||||
signature = git_commit_committer(commit);
|
signature = git_commit_committer(commit);
|
||||||
cl_assert_equal_s("foo@example.com", signature->email);
|
cl_assert_equal_s("foo@example.com", signature->email);
|
||||||
cl_assert_equal_s("<Yu V. Bin Haacked>", signature->name);
|
cl_assert_equal_s("Yu V. Bin Haacked", signature->name);
|
||||||
cl_assert_equal_i(1323847743, (int)signature->when.time);
|
cl_assert_equal_i(1323847743, (int)signature->when.time);
|
||||||
cl_assert_equal_i(60, signature->when.offset);
|
cl_assert_equal_i(60, signature->when.offset);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user