Bug Fix - blank annotations now disallowed

- Prevented blank annotations from being added, and the description
  being echoed as though it were the annotation applied (thanks to
  Bruce Dillahunty).
- Added bug.annotate.t unit test to prevent regression.
This commit is contained in:
Paul Beckingham 2009-05-27 01:01:25 -04:00
parent 8dd9690a65
commit 0fcaf85652
6 changed files with 73 additions and 10 deletions

View file

@ -13,6 +13,8 @@
+ Supports '--' argument to indicate that all subsequence arguments are
part of the description, despite what they otherwise might mean.
+ Removed support for the obsolete task file format 1 (never released).
+ Fixed bug that allowed blank annotations to be added (thanks to Bruce
Dillahunty),
------ old releases ------------------------------

View file

@ -143,6 +143,8 @@
<li>Supports '--' argument to indicate that all subsequence arguments are
part of the description, despite what they otherwise might mean.
<li>Removed support for the obsolete task file format 1 (never released).
<li>Fixed bug that allowed blank annotations to be added (thanks to Bruce
Dillahunty),
</ul>
<p>

View file

@ -584,16 +584,6 @@ void T::parse (const std::string& line)
// If this code is inaccurate, data corruption ensues.
int T::determineVersion (const std::string& line)
{
// Version 1 looks like:
//
// [tags] [attributes] description\n
// X [tags] [attributes] description\n
//
// Scan for the first character being either the bracket or X.
if ((line[0] == '[' && line[line.length () - 1] != ']') ||
line.find ("X [") != std::string::npos)
return 1;
// Version 2 looks like:
//
// uuid status [tags] [attributes] description\n
@ -627,6 +617,16 @@ int T::determineVersion (const std::string& line)
return 2;
}
// Version 1 looks like:
//
// [tags] [attributes] description\n
// X [tags] [attributes] description\n
//
// Scan for the first character being either the bracket or X.
else if ((line[0] == '[' && line[line.length () - 1] != ']') ||
line.find ("X [") == 0)
return 1;
// Version 4 looks like:
//
// [name:"value" ...]

View file

@ -948,6 +948,9 @@ std::string handleColor (Config& conf)
////////////////////////////////////////////////////////////////////////////////
std::string handleAnnotate (TDB& tdb, T& task, Config& conf)
{
if (task.getDescription () == "")
throw std::string ("Cannot apply a blank annotation.");
std::stringstream out;
std::vector <T> all;
tdb.pendingT (all);

View file

@ -153,6 +153,8 @@ void Context::loadCorrectConfigFile (int argc, char** argv)
std::string file = pw->pw_dir;
config.createDefault (file);
// TODO Apply overrides of type: "rc.name:value"
}
////////////////////////////////////////////////////////////////////////////////

54
src/tests/bug.annotate.t Executable file
View file

@ -0,0 +1,54 @@
#! /usr/bin/perl
################################################################################
## task - a command line task list manager.
##
## Copyright 2006 - 2009, Paul Beckingham.
## 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 => 4;
# Create the rc file.
if (open my $fh, '>', 'bug_annotate.rc')
{
print $fh "data.location=.\n";
close $fh;
ok (-r 'bug_annotate.rc', 'Created bug_annotate.rc');
}
# Attempt a blank annotation.
qx{../task rc:bug_annotate.rc add foo};
my $output = qx{../task rc:bug_annotate.rc 1 annotate};
like ($output, qr/Cannot apply a blank annotation./, 'failed on blank annotation');
# Cleanup.
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data');
unlink 'bug_annotate.rc';
ok (!-r 'bug_annotate.rc', 'Removed bug_annotate.rc');
exit 0;