mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
parseJSON: Allow annotations with missing entry values
This relaxes previous stringent requirements on the input values during import. Closes #1804.
This commit is contained in:
parent
6d81acd355
commit
8f7e41b392
1 changed files with 11 additions and 8 deletions
19
src/Task.cpp
19
src/Task.cpp
|
@ -758,14 +758,8 @@ void Task::parseJSON (const json::object* root_obj)
|
||||||
{
|
{
|
||||||
auto annotation = (json::object*)annotations;
|
auto annotation = (json::object*)annotations;
|
||||||
|
|
||||||
auto when = (json::string*)annotation->_data["entry"];
|
// Extract description. Fail if not present.
|
||||||
auto what = (json::string*)annotation->_data["description"];
|
auto what = (json::string*)annotation->_data["description"];
|
||||||
|
|
||||||
if (! when) {
|
|
||||||
annotation->_data.erase ("entry"); // Erase NULL entry inserted by failed lookup above
|
|
||||||
throw format ("Annotation is missing an entry date: {1}", annotation-> dump ());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! what) {
|
if (! what) {
|
||||||
annotation->_data.erase ("description"); // Erase NULL description inserted by failed lookup above
|
annotation->_data.erase ("description"); // Erase NULL description inserted by failed lookup above
|
||||||
throw format ("Annotation is missing a description: {1}", annotation->dump ());
|
throw format ("Annotation is missing a description: {1}", annotation->dump ());
|
||||||
|
@ -773,7 +767,16 @@ void Task::parseJSON (const json::object* root_obj)
|
||||||
|
|
||||||
// Extract 64-bit annotation entry value
|
// Extract 64-bit annotation entry value
|
||||||
// Time travelers from 2038, we have your back.
|
// Time travelers from 2038, we have your back.
|
||||||
long long ann_timestamp = (long long) (Datetime (when->_data).toEpoch ());
|
long long ann_timestamp;
|
||||||
|
|
||||||
|
// Extract entry. Use current time if not present.
|
||||||
|
auto when = (json::string*)annotation->_data["entry"];
|
||||||
|
if (when)
|
||||||
|
ann_timestamp = (long long) (Datetime (when->_data).toEpoch ());
|
||||||
|
else {
|
||||||
|
annotation->_data.erase ("entry"); // Erase NULL entry inserted by failed lookup above
|
||||||
|
ann_timestamp = (long long) (Datetime ().toEpoch ());
|
||||||
|
}
|
||||||
|
|
||||||
std::stringstream name;
|
std::stringstream name;
|
||||||
name << "annotation_" << ann_timestamp;
|
name << "annotation_" << ann_timestamp;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue