Report an error for incorrect dates like 2010/04/32
Fixes EF57C685-2C18-49A1-9A8C-FB3BE6F99C41
This commit is contained in:
parent
2034434653
commit
3e1ec40551
1 changed files with 34 additions and 20 deletions
32
src/times.cc
32
src/times.cc
|
|
@ -199,11 +199,9 @@ namespace {
|
||||||
{
|
{
|
||||||
date_t when;
|
date_t when;
|
||||||
|
|
||||||
if (std::strchr(date_str, '/')) {
|
|
||||||
when = io.parse(date_str);
|
|
||||||
} else {
|
|
||||||
char buf[128];
|
|
||||||
VERIFY(std::strlen(date_str) < 127);
|
VERIFY(std::strlen(date_str) < 127);
|
||||||
|
|
||||||
|
char buf[128];
|
||||||
std::strcpy(buf, date_str);
|
std::strcpy(buf, date_str);
|
||||||
|
|
||||||
for (char * p = buf; *p; p++)
|
for (char * p = buf; *p; p++)
|
||||||
|
|
@ -211,11 +209,22 @@ namespace {
|
||||||
*p = '/';
|
*p = '/';
|
||||||
|
|
||||||
when = io.parse(buf);
|
when = io.parse(buf);
|
||||||
}
|
|
||||||
|
|
||||||
if (! when.is_not_a_date()) {
|
if (! when.is_not_a_date()) {
|
||||||
DEBUG("times.parse", "Parsed date string: " << date_str);
|
DEBUG("times.parse", "Passed date string: " << date_str);
|
||||||
|
DEBUG("times.parse", "Parsed date string: " << buf);
|
||||||
DEBUG("times.parse", "Parsed result is: " << when);
|
DEBUG("times.parse", "Parsed result is: " << when);
|
||||||
|
DEBUG("times.parse", "Formatted result is: " << io.format(when));
|
||||||
|
|
||||||
|
const char * p = io.format(when).c_str();
|
||||||
|
const char * q = buf;
|
||||||
|
for (; *p != '\0' && *q != '\0';
|
||||||
|
p++, q++) {
|
||||||
|
if (*p != *q && *p == '0') p++;
|
||||||
|
if (*p != *q) break;
|
||||||
|
}
|
||||||
|
if (*p != '\0' || *q != '\0')
|
||||||
|
throw_(date_error, _("Invalid date: %1") << date_str);
|
||||||
|
|
||||||
if (traits)
|
if (traits)
|
||||||
*traits = io.traits;
|
*traits = io.traits;
|
||||||
|
|
@ -1299,14 +1308,14 @@ date_parser_t::lexer_t::token_t date_parser_t::lexer_t::next_token()
|
||||||
// "2009/08/01", but also dates that fit the user's --input-date-format,
|
// "2009/08/01", but also dates that fit the user's --input-date-format,
|
||||||
// assuming their format fits in one argument and begins with a digit.
|
// assuming their format fits in one argument and begins with a digit.
|
||||||
if (std::isdigit(*begin)) {
|
if (std::isdigit(*begin)) {
|
||||||
try {
|
|
||||||
string::const_iterator i = begin;
|
string::const_iterator i = begin;
|
||||||
for (i = begin; i != end && ! std::isspace(*i); i++) {}
|
for (i = begin; i != end && ! std::isspace(*i); i++) {}
|
||||||
assert(i != begin);
|
assert(i != begin);
|
||||||
|
|
||||||
string possible_date(start, i);
|
string possible_date(start, i);
|
||||||
date_traits_t traits;
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
date_traits_t traits;
|
||||||
date_t when = parse_date_mask(possible_date.c_str(), none, &traits);
|
date_t when = parse_date_mask(possible_date.c_str(), none, &traits);
|
||||||
if (! when.is_not_a_date()) {
|
if (! when.is_not_a_date()) {
|
||||||
begin = i;
|
begin = i;
|
||||||
|
|
@ -1314,7 +1323,12 @@ date_parser_t::lexer_t::token_t date_parser_t::lexer_t::next_token()
|
||||||
token_t::content_t(date_specifier_t(when, traits)));
|
token_t::content_t(date_specifier_t(when, traits)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (...) {}
|
catch (date_error&) {
|
||||||
|
if (contains(possible_date, "/") ||
|
||||||
|
contains(possible_date, "-") ||
|
||||||
|
contains(possible_date, "."))
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
start = begin;
|
start = begin;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue