Commit 6c0d5366 by Yoichi Nakayama

Cause error when date parsing is failed

parent 776a6a8e
...@@ -853,7 +853,7 @@ static git_time_t approxidate_str(const char *date, ...@@ -853,7 +853,7 @@ static git_time_t approxidate_str(const char *date,
} }
pending_number(&tm, &number); pending_number(&tm, &number);
if (!touched) if (!touched)
*error_ret = 1; *error_ret = -1;
return update_tm(&tm, &now, 0); return update_tm(&tm, &now, 0);
} }
...@@ -872,7 +872,7 @@ int git__date_parse(git_time_t *out, const char *date) ...@@ -872,7 +872,7 @@ int git__date_parse(git_time_t *out, const char *date)
return -1; return -1;
*out = approxidate_str(date, time_sec, &error_ret); *out = approxidate_str(date, time_sec, &error_ret);
return error_ret; return error_ret;
} }
int git__date_rfc2822_fmt(char *out, size_t len, const git_time *date) int git__date_rfc2822_fmt(char *out, size_t len, const git_time *date)
......
...@@ -348,8 +348,10 @@ static int handle_at_syntax(git_object **out, git_reference **ref, const char *s ...@@ -348,8 +348,10 @@ static int handle_at_syntax(git_object **out, git_reference **ref, const char *s
goto cleanup; goto cleanup;
} }
if (git__date_parse(&timestamp, curly_braces_content) < 0) if (git__date_parse(&timestamp, curly_braces_content) < 0) {
error = GIT_EINVALIDSPEC;
goto cleanup; goto cleanup;
}
error = retrieve_revobject_from_reflog(out, ref, repo, git_str_cstr(&identifier), (size_t)timestamp); error = retrieve_revobject_from_reflog(out, ref, repo, git_str_cstr(&identifier), (size_t)timestamp);
......
...@@ -13,3 +13,10 @@ void test_date_date__overflow(void) ...@@ -13,3 +13,10 @@ void test_date_date__overflow(void)
cl_assert(d2038 < d2039); cl_assert(d2038 < d2039);
#endif #endif
} }
void test_date_date__invalid_date(void)
{
git_time_t d;
cl_git_fail(git__date_parse(&d, ""));
cl_git_fail(git__date_parse(&d, "NEITHER_INTEGER_NOR_DATETIME"));
}
...@@ -460,6 +460,19 @@ void test_refs_revparse__date(void) ...@@ -460,6 +460,19 @@ void test_refs_revparse__date(void)
test_object("with-empty-log@{2 days ago}", NULL); test_object("with-empty-log@{2 days ago}", NULL);
} }
void test_refs_revparse__invalid_date(void)
{
/*
* $ git rev-parse HEAD@{} --
* fatal: bad revision 'HEAD@{}'
*
* $ git rev-parse HEAD@{NEITHER_INTEGER_NOR_DATETIME} --
* fatal: bad revision 'HEAD@{NEITHER_INTEGER_NOR_DATETIME}'
*/
test_object("HEAD@{}", NULL);
test_object("HEAD@{NEITHER_INTEGER_NOR_DATETIME}", NULL);
}
void test_refs_revparse__colon(void) void test_refs_revparse__colon(void)
{ {
assert_invalid_single_spec(":/"); assert_invalid_single_spec(":/");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment