GothenburgBitFactory / GothenburgBitFactory/taskwarrior

Some invalid datetimes are not detected early enough

Open
#2,996 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
6.1k
Forks
423
Avg merge
1d 19h
Merged PRs (30d)
11

Description

`./test/datetime-negative.t` tests that a bunch of invalid dates result in errors. The tests pass, but many of them only by accident. Consider

```
⸩ task add due:-12:12:12+01:00 foo
'-1668769932' is not a valid date in the '' format.
```
this is, indeed, an error, as the test expects. However:
* the input was not `-1668769932`; and
* the date format is not `''`

It turns out that there are two places where an identical "is not a valid date in the" is thrown:
* `src/columns/ColTypeDate.cpp`
* `src/libshared/src/Datetime.cpp`

many of the cases in this test script are caught in the first spot, which is the expectation. However, when the input evaluates as an arithmetic expression and the result is not 0, `ColTypeDate.cpp` lets it pass. This date is then added to the new task, and only when that task is written to the backlog, via `Task::composeJSON`, is the error thrown.

So, I think we need to do a better job of validating the input in `ColTypeDate.cpp`, preferably by calling the Datetime constructor to raise the exception in only that one spot. However, I don't understand the Variant implementation well enough to know how to do that. Can someone help me out?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.