From a99aa217d068b4de865d34bbbeca092df84b95fc Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 28 Sep 2011 23:26:07 -0400 Subject: [PATCH] Bug #856 - Fixed bug #856, which prevented filters on missing project from working (thanks to Michelle Crane). --- ChangeLog | 2 ++ src/E9.cpp | 27 +++++++++++++++----- test/bug.856.t | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 7 deletions(-) create mode 100755 test/bug.856.t diff --git a/ChangeLog b/ChangeLog index 278864e33..2fab7833e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -195,6 +195,8 @@ Gour D). + Fixed bug #846, which prevented the default.command configuration from handling multiple arguments (thanks to Uli Martens). + + Fixed bug #856, which prevented filters on missing project from working + (thanks to Michelle Crane). # Untracked Bugs, biggest first. + Fixed bug that required the '%YAML' prologue in a YAML import. diff --git a/src/E9.cpp b/src/E9.cpp index 72385e652..6692ceb58 100644 --- a/src/E9.cpp +++ b/src/E9.cpp @@ -472,14 +472,27 @@ void E9::operator_equal ( // 'project' is matched leftmost. if (left._raw == "project") { - unsigned int right_len = right._value.length (); - if (compare (right._value, - (right_len < left._value.length () - ? left._value.substr (0, right_len) - : left._value), - case_sensitive)) + // Bug 856. + // + // Special case for checking absent projects. Without the explicit "" check + // the right._value.lenghth() is used, which is 0, and therefore generates + // a false match. + if (right._value == "") { - result._value = "true"; + if (left._value == "") + result._value = "true"; + } + else + { + unsigned int right_len = right._value.length (); + if (compare (right._value, + (right_len < left._value.length () + ? left._value.substr (0, right_len) + : left._value), + case_sensitive)) + { + result._value = "true"; + } } } diff --git a/test/bug.856.t b/test/bug.856.t new file mode 100755 index 000000000..9abab2ae4 --- /dev/null +++ b/test/bug.856.t @@ -0,0 +1,69 @@ +#! /usr/bin/perl +################################################################################ +## taskwarrior - a command line task list manager. +## +## Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez. +## All rights reserved. +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 2 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, write to the +## +## Free Software Foundation, Inc., +## 51 Franklin Street, Fifth Floor, +## Boston, MA +## 02110-1301 +## USA +## +################################################################################ + +use strict; +use warnings; +use Test::More tests => 8; + +# Create the rc file. +if (open my $fh, '>', 'bug.rc') +{ + print $fh "data.location=.\n"; + close $fh; + ok (-r 'bug.rc', 'Created bug.rc'); +} + +# Bug 856: "task list project.none:" does not work. +# Note: Not using "assigned" and "unassigned" because one is a subset of the +# other. +qx{../src/task rc:bug.rc add assigned project:X}; +qx{../src/task rc:bug.rc add floating}; + +my $output = qx{../src/task rc:bug.rc ls project:}; +like ($output, qr/floating/, 'project: matches floating'); +unlike ($output, qr/assigned/, 'project: does not match assigned'); + +$output = qx{../src/task rc:bug.rc ls project:''}; +like ($output, qr/floating/, 'project:\'\' matches floating'); +unlike ($output, qr/assigned/, 'project:\'\' does not match assigned'); + +$output = qx{../src/task rc:bug.rc ls project.none:}; +like ($output, qr/floating/, 'project.none: matches floating'); +unlike ($output, qr/assigned/, 'project.none: does not match assigned'); + +# Cleanup. +unlink qw(pending.data completed.data undo.data backlog.data synch.key bug.rc); +ok (! -r 'pending.data' && + ! -r 'completed.data' && + ! -r 'undo.data' && + ! -r 'backlog.data' && + ! -r 'synch.key' && + ! -r 'bug.rc', 'Cleanup'); + +exit 0; +