From d49a2614ba42e13fc5b19e3e3e62d54cf7128cc2 Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Mon, 20 Oct 2014 20:21:11 +0100 Subject: [PATCH] Bug - import/export now output JSON as individual objects * For JSON as array, json.array=1 behaves as before * Tests and add-on scripts used in import tests were updated --- scripts/add-ons/import-todo.sh.pl | 2 +- scripts/add-ons/import-yaml.pl | 2 +- src/commands/CmdExport.cpp | 6 +++++- src/commands/CmdImport.cpp | 3 +-- test/import.t | 4 ++-- test/uda_orphan.t | 2 +- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/scripts/add-ons/import-todo.sh.pl b/scripts/add-ons/import-todo.sh.pl index cf4d1c3bb..6310459e7 100755 --- a/scripts/add-ons/import-todo.sh.pl +++ b/scripts/add-ons/import-todo.sh.pl @@ -125,7 +125,7 @@ while (my $todo = <>) push @tasks, $json; } -print "[\n", join (",\n", @tasks), "\n]\n"; +print "[\n", join ("\n", @tasks), "\n]\n"; exit 0; ################################################################################ diff --git a/scripts/add-ons/import-yaml.pl b/scripts/add-ons/import-yaml.pl index 5c73b7ea2..94179c74f 100755 --- a/scripts/add-ons/import-yaml.pl +++ b/scripts/add-ons/import-yaml.pl @@ -117,7 +117,7 @@ while (my $yaml = <>) } } -print "[\n", join (",\n", @tasks), "\n]\n"; +print "[\n", join ("\n", @tasks), "\n]\n"; exit 0; ################################################################################ diff --git a/src/commands/CmdExport.cpp b/src/commands/CmdExport.cpp index 06f0b6709..82fdd4c7b 100644 --- a/src/commands/CmdExport.cpp +++ b/src/commands/CmdExport.cpp @@ -71,7 +71,11 @@ int CmdExport::execute (std::string& output) for (task = filtered.begin (); task != filtered.end (); ++task) { if (task != filtered.begin ()) - output += ",\n"; + { + if (json_array) + output += ","; + output += "\n"; + } output += task->composeJSON (true); diff --git a/src/commands/CmdImport.cpp b/src/commands/CmdImport.cpp index 2f5595732..07f3b2494 100644 --- a/src/commands/CmdImport.cpp +++ b/src/commands/CmdImport.cpp @@ -76,8 +76,7 @@ int CmdImport::execute (std::string& output) { std::string object = trimLeft ( trimRight ( - trimRight ( - trim (*line), ","), + trim (*line), "]"), "["); // Skip blanks. May be caused by the trim calls above. diff --git a/test/import.t b/test/import.t index 9360f62b9..e6c77fe19 100755 --- a/test/import.t +++ b/test/import.t @@ -45,8 +45,8 @@ if (open my $fh, '>', 'import.rc') if (open my $fh, '>', 'import.txt') { print $fh <', 'import.txt') { print $fh <