From 1355571876d421fecfcb425b5792ab89ed59b56f Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 5 Aug 2009 10:15:33 -0600 Subject: [PATCH] Bug Fix - #252 - Fixed bug that prevented the chaining of two attributes with different modifiers to effect a date range, such as: task ls due.after:8/1/2009 due.before:8/31/2009 Thanks to John Florian. --- ChangeLog | 3 +++ src/Context.cpp | 25 +++++++++++++++---------- src/Filter.cpp | 2 +- src/Task.cpp | 4 ++-- src/command.cpp | 23 ++++++----------------- src/tests/att.t.cpp | 14 +++++++------- src/tests/custom.recur_ind.t | 2 +- 7 files changed, 35 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index f7e22b26c..f00310160 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,6 +17,9 @@ for colored header and footnotes (thanks to John Florian). + Fixed bug #248 where single and double quotes are both stored as ampersand-quot-semi (thanks to John Florian). + + Fixed bug #252 that prevented use of attribute modifiers on dates to effect + a range, such as "task ls due.after:eom due.before:eoy" (thanks to John + Florian). ------ old releases ------------------------------ diff --git a/src/Context.cpp b/src/Context.cpp index cc2a472c6..fbd8bd73a 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -539,7 +539,12 @@ void Context::parse ( attribute.mod (mod); attribute.value (value); - parseTask[attribute.name ()] = attribute; + // Preserve modifier in the key, to allow multiple modifiers on the + // same attribute. Bug #252. + if (name != "" && mod != "") + parseTask[name + "." + mod] = attribute; + else + parseTask[name] = attribute; } // *arg has the appearance of an attribute (foo:bar), but isn't @@ -668,46 +673,46 @@ void Context::autoFilter (Task& t, Filter& f) foreach (att, t) { // Words are found in the description using the .has modifier. - if (att->first == "description" && att->second.mod () == "") + if (att->second.name () == "description" && att->second.mod () == "") { std::vector words; split (words, att->second.value (), ' '); foreach (word, words) { f.push_back (Att ("description", "has", *word)); - debug ("auto filter: " + att->first + ".has:" + *word); + debug ("auto filter: " + att->second.name () + ".has:" + *word); } } // Projects are matched left-most. - else if (att->first == "project" && att->second.mod () == "") + else if (att->second.name () == "project" && att->second.mod () == "") { if (att->second.value () != "") { f.push_back (Att ("project", "startswith", att->second.value ())); - debug ("auto filter: " + att->first + ".startswith:" + att->second.value ()); + debug ("auto filter: " + att->second.name () + ".startswith:" + att->second.value ()); } else { f.push_back (Att ("project", "is", att->second.value ())); - debug ("auto filter: " + att->first + ".is:" + att->second.value ()); + debug ("auto filter: " + att->second.name () + ".is:" + att->second.value ()); } } // The limit attribute does not participate in filtering, and needs to be // specifically handled in handleCustomReport. - else if (att->first == "limit") + else if (att->second.name () == "limit") { } // Every task has a unique uuid by default, and it shouldn't be included, // because it is guaranteed to not match. - else if (att->first == "uuid") + else if (att->second.name () == "uuid") { } // The mechanism for filtering on tags is +/-. - else if (att->first == "tags") + else if (att->second.name () == "tags") { } @@ -716,7 +721,7 @@ void Context::autoFilter (Task& t, Filter& f) { f.push_back (att->second); debug ("auto filter: " + - att->first + + att->second.name () + (att->second.mod () != "" ? ("." + att->second.mod () + ":") : ":") + diff --git a/src/Filter.cpp b/src/Filter.cpp index 340dd1f60..79f800372 100644 --- a/src/Filter.cpp +++ b/src/Filter.cpp @@ -70,7 +70,7 @@ bool Filter::pass (const Record& record) const return false; } - // Annotations are skipped. + // Annotations are skipped, because they are handled above. else if (att->name ().length () > 11 && att->name ().substr (0, 11) == "annotation_") { diff --git a/src/Task.cpp b/src/Task.cpp index 940cd2b63..68bf75766 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -67,8 +67,8 @@ bool Task::operator== (const Task& other) return false; foreach (att, *this) - if (att->first != "uuid") - if (att->second.value () != other.get (att->first)) + if (att->second.name () != "uuid") + if (att->second.value () != other.get (att->second.name ())) return false; return true; diff --git a/src/command.cpp b/src/command.cpp index a08503522..26e551817 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -103,7 +103,6 @@ std::string handleAdd () // All this, just for an id number. std::vector all; Filter none; - handleRecurrence (); context.tdb.loadPending (all, none); out << "Created task " << context.tdb.nextId () << std::endl; #endif @@ -123,7 +122,6 @@ std::string handleProjects () std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); - handleRecurrence (); int quantity = context.tdb.loadPending (tasks, context.filter); context.tdb.commit (); context.tdb.unlock (); @@ -209,7 +207,6 @@ std::string handleCompletionProjects () { std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); - handleRecurrence (); Filter filter; if (context.config.get (std::string ("complete.all.projects"), false)) @@ -243,7 +240,6 @@ std::string handleTags () std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); - handleRecurrence (); int quantity = context.tdb.loadPending (tasks, context.filter); context.tdb.commit (); context.tdb.unlock (); @@ -306,7 +302,6 @@ std::string handleCompletionTags () { std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); - handleRecurrence (); Filter filter; if (context.config.get (std::string ("complete.all.tags"), false)) @@ -369,7 +364,6 @@ std::string handleCompletionIDs () { std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); - handleRecurrence (); Filter filter; context.tdb.loadPending (tasks, filter); context.tdb.commit (); @@ -565,7 +559,6 @@ std::string handleDelete () std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); - handleRecurrence (); Filter filter; context.tdb.loadPending (tasks, filter); @@ -665,7 +658,6 @@ std::string handleStart () std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); - handleRecurrence (); Filter filter; context.tdb.loadPending (tasks, filter); @@ -717,7 +709,6 @@ std::string handleStop () std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); - handleRecurrence (); Filter filter; context.tdb.loadPending (tasks, filter); @@ -764,7 +755,6 @@ std::string handleDone () std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); - handleRecurrence (); Filter filter; context.tdb.loadPending (tasks, filter); @@ -895,7 +885,6 @@ std::string handleModify () std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); - handleRecurrence (); Filter filter; context.tdb.loadPending (tasks, filter); @@ -973,7 +962,6 @@ std::string handleAppend () std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); - handleRecurrence (); Filter filter; context.tdb.loadPending (tasks, filter); @@ -1369,12 +1357,12 @@ int deltaAttributes (Task& task) foreach (att, context.task) { - if (att->first != "uuid" && - att->first != "description" && - att->first != "tags") + if (att->second.name () != "uuid" && + att->second.name () != "description" && + att->second.name () != "tags") { // Modifying "wait" changes status. - if (att->first == "wait") + if (att->second.name () == "wait") { if (att->second.value () == "") task.setStatus (Task::pending); @@ -1383,8 +1371,9 @@ int deltaAttributes (Task& task) } if (att->second.value () == "") - task.remove (att->first); + task.remove (att->second.name ()); else + // One of the few places where the compound attribute name is used. task.set (att->first, att->second.value ()); ++changes; diff --git a/src/tests/att.t.cpp b/src/tests/att.t.cpp index f50c0e55d..11f17ef78 100644 --- a/src/tests/att.t.cpp +++ b/src/tests/att.t.cpp @@ -75,9 +75,9 @@ int main (int argc, char** argv) Att a5 ("name", "value"); t.is (a5.composeF4 (), "name:\"value\"", "Att::composeF4 simple"); a5.value ("\""); - t.is (a5.composeF4 (), "name:\""\"", "Att::composeF4 encoded \""); + t.is (a5.composeF4 (), "name:\"&dquot;\"", "Att::composeF4 encoded \""); a5.value ("\t\",[]:"); - t.is (a5.composeF4 (), "name:\"&tab;",&open;&close;:\"", "Att::composeF4 fully encoded \\t\",[]:"); + t.is (a5.composeF4 (), "name:\"&tab;&dquot;,&open;&close;:\"", "Att::composeF4 fully encoded \\t\",[]:"); Att a6 ("name", 6); t.is (a6.value_int (), 6, "Att::value_int get"); @@ -174,12 +174,12 @@ int main (int argc, char** argv) n = Nibbler ("name:\""\""); a7.parse (n); - t.is (a7.composeF4 (), "name:\""\"", + t.is (a7.composeF4 (), "name:\"&dquot;\"", "Att::parse (name:\""\")"); n = Nibbler ("name:\"&tab;",&open;&close;:\""); a7.parse (n); - t.is (a7.composeF4 (), "name:\"&tab;",&open;&close;:\"", + t.is (a7.composeF4 (), "name:\"&tab;&dquot;,&open;&close;:\"", "Att::parse (name:\"&tab;",&open;&close;:\")"); n = Nibbler ("total gibberish"); @@ -216,19 +216,19 @@ int main (int argc, char** argv) good = true; try {a7.parse (n);} catch (...) {good = false;} t.ok (good, "Att::parse (name:\"value)"); - t.is (a7.composeF4 (), "name:\""value\"", "Att::composeF4 -> name:\""value\""); + t.is (a7.composeF4 (), "name:\"&dquot;value\"", "Att::composeF4 -> name:\"&dquot;value\""); n = Nibbler ("name:value\""); good = true; try {a7.parse (n);} catch (...) {good = false;} t.ok (good, "Att::parse (name:value\")"); - t.is (a7.composeF4 (), "name:\"value"\"", "Att::composeF4 -> name:\"value"\""); + t.is (a7.composeF4 (), "name:\"value&dquot;\"", "Att::composeF4 -> name:\"value&dquot;\""); n = Nibbler ("name:val\"ue"); good = true; try {a7.parse (n);} catch (...) {good = false;} t.ok (good, "Att::parse (name:val\"ue)"); - t.is (a7.composeF4 (), "name:\"val"ue\"", "Att::composeF4 -> name:\"val"ue\""); + t.is (a7.composeF4 (), "name:\"val&dquot;ue\"", "Att::composeF4 -> name:\"val&dquot;ue\""); n = Nibbler ("name\""); good = true; diff --git a/src/tests/custom.recur_ind.t b/src/tests/custom.recur_ind.t index d1bf096cb..75cc2da2e 100755 --- a/src/tests/custom.recur_ind.t +++ b/src/tests/custom.recur_ind.t @@ -42,7 +42,7 @@ if (open my $fh, '>', 'custom.rc') ok (-r 'custom.rc', 'Created custom.rc'); } -# Generate the usage screen, and locate the custom report on it. +# Add a recurring and non-recurring task, look for the indicator. qx{../task rc:custom.rc add foo due:tomorrow recur:weekly}; qx{../task rc:custom.rc add bar}; my $output = qx{../task rc:custom.rc foo 2>&1};