mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Generate valid JSON even with invalid dates (#3801)
This commit is contained in:
parent
022650dbff
commit
74276b400c
2 changed files with 8 additions and 2 deletions
|
@ -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)
|
||||
<< '"';
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ import sys
|
|||
import os
|
||||
import re
|
||||
import time
|
||||
import json
|
||||
import unittest
|
||||
|
||||
# Ensure python finds the local simpletap module
|
||||
|
@ -192,6 +193,7 @@ class TestUnusualTasks(TestCase):
|
|||
modified="modified",
|
||||
)
|
||||
_, out, _ = self.t(f"{uuid} export")
|
||||
json.loads(out)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue