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

Skip to content

signature: Strip crud #3478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/index.c
Original file line number Diff line number Diff line change
Expand Up @@ -1193,13 +1193,13 @@ static int index_no_dups(void **old, void *new)
}

static void index_existing_and_best(
const git_index_entry **existing,
git_index_entry **existing,
size_t *existing_position,
const git_index_entry **best,
git_index_entry **best,
git_index *index,
const git_index_entry *entry)
{
const git_index_entry *e;
git_index_entry *e;
size_t pos;
int error;

Expand Down
18 changes: 16 additions & 2 deletions src/signature.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,27 @@ static bool contains_angle_brackets(const char *input)
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)
{
while (len && git__isspace(ptr[0])) {
while (len && is_crud((unsigned char)ptr[0])) {
ptr++; len--;
}

while (len && git__isspace(ptr[len - 1])) {
while (len && is_crud((unsigned char)ptr[len - 1])) {
len--;
}

Expand Down
7 changes: 7 additions & 0 deletions tests/commit/signature.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ void test_commit_signature__leading_and_trailing_spaces_are_trimmed(void)
assert_name_and_email("nulltoken", "[email protected]", " \t nulltoken \n", " \n [email protected] \n");
}

void test_commit_signature__leading_and_trailing_crud_is_trimmed(void)
{
assert_name_and_email("nulltoken", "[email protected]", "\"nulltoken\"", "\"[email protected]\"");
assert_name_and_email("nulltoken w", "[email protected]", "nulltoken w.", "[email protected]");
assert_name_and_email("nulltoken \xe2\x98\xba", "[email protected]", "nulltoken \xe2\x98\xba", "[email protected]");
}

void test_commit_signature__angle_brackets_in_names_are_not_supported(void)
{
cl_git_fail(try_build_signature("<Phil Haack", "phil@haack", 1234567890, 60));
Expand Down
2 changes: 1 addition & 1 deletion tests/diff/workdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -2080,7 +2080,7 @@ void test_diff_workdir__to_index_pathlist(void)
cl_git_pass(git_repository_index(&index, g_repo));

opts.flags = GIT_DIFF_INCLUDE_IGNORED;
opts.pathspec.strings = pathlist.contents;
opts.pathspec.strings = (char **)pathlist.contents;
opts.pathspec.count = pathlist.length;

cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, index, &opts));
Expand Down
3 changes: 2 additions & 1 deletion tests/revwalk/basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,8 @@ void test_revwalk_basic__big_timestamp(void)
cl_git_pass(git_signature_new(&sig, "Joe", "[email protected]", 2399662595, 0));
cl_git_pass(git_commit_tree(&tree, tip));

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

cl_git_pass(git_revwalk_push_head(_walk));

Expand Down
2 changes: 1 addition & 1 deletion tests/revwalk/signatureparsing.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void test_revwalk_signatureparsing__do_not_choke_when_name_contains_angle_bracke

signature = git_commit_committer(commit);
cl_assert_equal_s("[email protected]", 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(60, signature->when.offset);

Expand Down