signature.c: fix off-by-one error Signed-off-by: schu <schu-github@schulog.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
diff --git a/src/signature.c b/src/signature.c
index cc55d1d..7116db5 100644
--- a/src/signature.c
+++ b/src/signature.c
@@ -62,7 +62,7 @@ static int process_trimming(const char *input, char **storage, const char *input
left = skip_leading_spaces(input, input_end);
right = skip_trailing_spaces(input, input_end - 1);
- if (right <= left) {
+ if (right < left) {
if (fail_when_empty)
return git__throw(GIT_EINVALIDARGS, "Failed to trim. Input is either empty or only contains spaces");
else
diff --git a/tests/t04-commit.c b/tests/t04-commit.c
index 53f0fae..3b327ec 100644
--- a/tests/t04-commit.c
+++ b/tests/t04-commit.c
@@ -478,6 +478,31 @@ BEGIN_TEST(signature1, "can not create a signature with empty name or email")
must_fail(try_build_signature("nulltoken", " ", 1234567890, 60));
END_TEST
+BEGIN_TEST(signature2, "creating a one character signature")
+ git_signature *sign;
+ sign = git_signature_new("x", "foo@bar.baz", 1234567890, 60);
+ must_be_true(sign != NULL);
+ must_pass(strcmp(sign->name, "x"));
+ must_pass(strcmp(sign->email, "foo@bar.baz"));
+ git_signature_free((git_signature *)sign);
+END_TEST
+
+BEGIN_TEST(signature3, "creating a two character signature")
+ git_signature *sign;
+ sign = git_signature_new("xx", "x@y.z", 1234567890, 60);
+ must_be_true(sign != NULL);
+ must_pass(strcmp(sign->name, "x"));
+ must_pass(strcmp(sign->email, "foo@bar.baz"));
+ git_signature_free((git_signature *)sign);
+END_TEST
+
+BEGIN_TEST(signature4, "creating a zero character signature")
+ git_signature *sign;
+ sign = git_signature_new("", "x@y.z", 1234567890, 60);
+ must_be_true(sign == NULL);
+END_TEST
+
+
/* External declaration for testing the buffer parsing method */
int commit_parse_buffer(git_commit *commit, void *data, size_t len, unsigned int parse_flags);
@@ -758,4 +783,7 @@ BEGIN_SUITE(commit)
ADD_TEST(signature0);
ADD_TEST(signature1);
+ ADD_TEST(signature2);
+ ADD_TEST(signature3);
+ ADD_TEST(signature4);
END_SUITE