Generate valid JSON even with invalid dates (#3801)

This commit is contained in:
Dustin J. Mitchell 2025-03-06 10:59:14 -05:00 committed by GitHub
parent 022650dbff
commit 74276b400c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View file

@ -798,8 +798,6 @@ std::string Task::composeJSON(bool decorate /*= false*/) const {
// If value is an empty string, do not ever output it
if (i.second == "") continue;
if (attributes_written) out << ',';
std::string type = Task::attributes[i.first];
if (type == "") type = "string";
@ -808,6 +806,8 @@ std::string Task::composeJSON(bool decorate /*= false*/) const {
time_t epoch = get_date(i.first);
if (epoch != 0) {
Datetime d(i.second);
if (attributes_written) out << ',';
out << '"' << (i.first == "modification" ? "modified" : i.first)
<< "\":\""
// Date was deleted, do not export parsed empty string
@ -824,6 +824,8 @@ std::string Task::composeJSON(bool decorate /*= false*/) const {
}
*/
else if (type == "numeric") {
if (attributes_written) out << ',';
out << '"' << i.first << "\":" << i.second;
++attributes_written;
@ -831,6 +833,8 @@ std::string Task::composeJSON(bool decorate /*= false*/) const {
// Everything else is a quoted value.
else {
if (attributes_written) out << ',';
out << '"' << i.first << "\":\"" << (type == "string" ? json::encode(i.second) : i.second)
<< '"';