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 value is an empty string, do not ever output it
|
||||||
if (i.second == "") continue;
|
if (i.second == "") continue;
|
||||||
|
|
||||||
if (attributes_written) out << ',';
|
|
||||||
|
|
||||||
std::string type = Task::attributes[i.first];
|
std::string type = Task::attributes[i.first];
|
||||||
if (type == "") type = "string";
|
if (type == "") type = "string";
|
||||||
|
|
||||||
|
@ -808,6 +806,8 @@ std::string Task::composeJSON(bool decorate /*= false*/) const {
|
||||||
time_t epoch = get_date(i.first);
|
time_t epoch = get_date(i.first);
|
||||||
if (epoch != 0) {
|
if (epoch != 0) {
|
||||||
Datetime d(i.second);
|
Datetime d(i.second);
|
||||||
|
if (attributes_written) out << ',';
|
||||||
|
|
||||||
out << '"' << (i.first == "modification" ? "modified" : i.first)
|
out << '"' << (i.first == "modification" ? "modified" : i.first)
|
||||||
<< "\":\""
|
<< "\":\""
|
||||||
// Date was deleted, do not export parsed empty string
|
// 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") {
|
else if (type == "numeric") {
|
||||||
|
if (attributes_written) out << ',';
|
||||||
|
|
||||||
out << '"' << i.first << "\":" << i.second;
|
out << '"' << i.first << "\":" << i.second;
|
||||||
|
|
||||||
++attributes_written;
|
++attributes_written;
|
||||||
|
@ -831,6 +833,8 @@ std::string Task::composeJSON(bool decorate /*= false*/) const {
|
||||||
|
|
||||||
// Everything else is a quoted value.
|
// Everything else is a quoted value.
|
||||||
else {
|
else {
|
||||||
|
if (attributes_written) out << ',';
|
||||||
|
|
||||||
out << '"' << i.first << "\":\"" << (type == "string" ? json::encode(i.second) : i.second)
|
out << '"' << i.first << "\":\"" << (type == "string" ? json::encode(i.second) : i.second)
|
||||||
<< '"';
|
<< '"';
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ import sys
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
import json
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
# Ensure python finds the local simpletap module
|
# Ensure python finds the local simpletap module
|
||||||
|
@ -192,6 +193,7 @@ class TestUnusualTasks(TestCase):
|
||||||
modified="modified",
|
modified="modified",
|
||||||
)
|
)
|
||||||
_, out, _ = self.t(f"{uuid} export")
|
_, out, _ = self.t(f"{uuid} export")
|
||||||
|
json.loads(out)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue