From 0c1fa8b20e9238eeac34ee6dabcdc05f1b3a9f10 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 6 Jul 2014 12:14:44 -0400 Subject: [PATCH] TW-288 - TW-288 `task edit` mangles descriptions with embedded newlines (thanks to Kevin Ballard). --- AUTHORS | 1 + ChangeLog | 2 ++ src/commands/CmdEdit.cpp | 24 ++++++++++++++++++++++-- src/commands/CmdEdit.h | 1 + 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index 6548d6b8c..034553b80 100644 --- a/AUTHORS +++ b/AUTHORS @@ -220,3 +220,4 @@ suggestions: Will Dietz Charles Ulrich Jack + Kevin Ballard diff --git a/ChangeLog b/ChangeLog index df304c001..06c4298e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -63,6 +63,8 @@ - TW-279 ".monthly" unexpectedly appended to task annotation (thanks to Florian Hollerweger). - TW-285 DUETODAY doesn't give any output (thanks to Jostein Berntsen). +- TW-288 `task edit` mangles descriptions with embedded newlines (thanks to + Kevin Ballard). - TW-294 Display UUID of task created by add (thanks to John West). - TW-306 Wrong date format in burndown view (thanks to Michele Santullo). - TW-752 task ID no longer defaults to info (thanks to Christopher Roberts). diff --git a/src/commands/CmdEdit.cpp b/src/commands/CmdEdit.cpp index 22b323a11..2edd93efc 100644 --- a/src/commands/CmdEdit.cpp +++ b/src/commands/CmdEdit.cpp @@ -97,6 +97,26 @@ std::string CmdEdit::findValue ( return ""; } +//////////////////////////////////////////////////////////////////////////////// +std::string CmdEdit::findMultilineValue ( + const std::string& text, + const std::string& startMarker, + const std::string& endMarker) +{ + std::string::size_type start = text.find (startMarker); + if (start != std::string::npos) + { + std::string::size_type end = text.find (endMarker, start); + if (end != std::string::npos) + { + std::string value = text.substr (start + startMarker.length (), + end - (start + startMarker.length ())); + return trim (value, "\t "); + } + } + return ""; +} + //////////////////////////////////////////////////////////////////////////////// std::vector CmdEdit::findValues ( const std::string& text, @@ -351,7 +371,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string task.addTags (tags); // description. - value = findValue (after, "\n Description:"); + value = findMultilineValue (after, "\n Description:", "\n Created:"); if (task.get ("description") != value) { if (value != "") @@ -717,7 +737,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string } } } - + // UDA orphans std::vector orphanValues = findValues (after, "\n UDA Orphan "); std::vector ::iterator orphan; diff --git a/src/commands/CmdEdit.h b/src/commands/CmdEdit.h index 37d7cca95..788c9ff33 100644 --- a/src/commands/CmdEdit.h +++ b/src/commands/CmdEdit.h @@ -39,6 +39,7 @@ public: private: std::string findValue (const std::string&, const std::string&); + std::string findMultilineValue (const std::string&, const std::string&, const std::string&); std::vector findValues (const std::string&, const std::string&); std::string formatDate (Task&, const std::string&, const std::string&); std::string formatDuration (Task&, const std::string&);