Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 855f048

Browse files
author
Vicent Marti
committed
Merge pull request libgit2#3478 from libgit2/vmg/crud
signature: Strip crud
2 parents 4280fab + bbe1957 commit 855f048

File tree

6 files changed

+30
-8
lines changed

6 files changed

+30
-8
lines changed

src/index.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,13 +1193,13 @@ static int index_no_dups(void **old, void *new)
11931193
}
11941194

11951195
static void index_existing_and_best(
1196-
const git_index_entry **existing,
1196+
git_index_entry **existing,
11971197
size_t *existing_position,
1198-
const git_index_entry **best,
1198+
git_index_entry **best,
11991199
git_index *index,
12001200
const git_index_entry *entry)
12011201
{
1202-
const git_index_entry *e;
1202+
git_index_entry *e;
12031203
size_t pos;
12041204
int error;
12051205

src/signature.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,27 @@ static bool contains_angle_brackets(const char *input)
3434
return strchr(input, '<') != NULL || strchr(input, '>') != NULL;
3535
}
3636

37+
static bool is_crud(unsigned char c)
38+
{
39+
return c <= 32 ||
40+
c == '.' ||
41+
c == ',' ||
42+
c == ':' ||
43+
c == ';' ||
44+
c == '<' ||
45+
c == '>' ||
46+
c == '"' ||
47+
c == '\\' ||
48+
c == '\'';
49+
}
50+
3751
static char *extract_trimmed(const char *ptr, size_t len)
3852
{
39-
while (len && git__isspace(ptr[0])) {
53+
while (len && is_crud((unsigned char)ptr[0])) {
4054
ptr++; len--;
4155
}
4256

43-
while (len && git__isspace(ptr[len - 1])) {
57+
while (len && is_crud((unsigned char)ptr[len - 1])) {
4458
len--;
4559
}
4660

tests/commit/signature.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ void test_commit_signature__leading_and_trailing_spaces_are_trimmed(void)
3535
assert_name_and_email("nulltoken", "[email protected]", " \t nulltoken \n", " \n [email protected] \n");
3636
}
3737

38+
void test_commit_signature__leading_and_trailing_crud_is_trimmed(void)
39+
{
40+
assert_name_and_email("nulltoken", "[email protected]", "\"nulltoken\"", "\"[email protected]\"");
41+
assert_name_and_email("nulltoken w", "[email protected]", "nulltoken w.", "[email protected]");
42+
assert_name_and_email("nulltoken \xe2\x98\xba", "[email protected]", "nulltoken \xe2\x98\xba", "[email protected]");
43+
}
44+
3845
void test_commit_signature__angle_brackets_in_names_are_not_supported(void)
3946
{
4047
cl_git_fail(try_build_signature("<Phil Haack", "phil@haack", 1234567890, 60));

tests/diff/workdir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2080,7 +2080,7 @@ void test_diff_workdir__to_index_pathlist(void)
20802080
cl_git_pass(git_repository_index(&index, g_repo));
20812081

20822082
opts.flags = GIT_DIFF_INCLUDE_IGNORED;
2083-
opts.pathspec.strings = pathlist.contents;
2083+
opts.pathspec.strings = (char **)pathlist.contents;
20842084
opts.pathspec.count = pathlist.length;
20852085

20862086
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, index, &opts));

tests/revwalk/basic.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,8 @@ void test_revwalk_basic__big_timestamp(void)
456456
cl_git_pass(git_signature_new(&sig, "Joe", "[email protected]", 2399662595, 0));
457457
cl_git_pass(git_commit_tree(&tree, tip));
458458

459-
cl_git_pass(git_commit_create(&id, _repo, "HEAD", sig, sig, NULL, "some message", tree, 1, &tip));
459+
cl_git_pass(git_commit_create(&id, _repo, "HEAD", sig, sig, NULL, "some message", tree, 1,
460+
(const git_commit **)&tip));
460461

461462
cl_git_pass(git_revwalk_push_head(_walk));
462463

tests/revwalk/signatureparsing.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void test_revwalk_signatureparsing__do_not_choke_when_name_contains_angle_bracke
3838

3939
signature = git_commit_committer(commit);
4040
cl_assert_equal_s("[email protected]", signature->email);
41-
cl_assert_equal_s("<Yu V. Bin Haacked>", signature->name);
41+
cl_assert_equal_s("Yu V. Bin Haacked", signature->name);
4242
cl_assert_equal_i(1323847743, (int)signature->when.time);
4343
cl_assert_equal_i(60, signature->when.offset);
4444

0 commit comments

Comments
 (0)