diff --git a/src/TaskManager.php b/src/TaskManager.php index 4df81d8..4ab73ae 100644 --- a/src/TaskManager.php +++ b/src/TaskManager.php @@ -21,6 +21,8 @@ use JMS\Serializer\SerializerBuilder; */ class TaskManager { + const PATTERN = '/^[\wäüö]*$/i'; + /** * @var Taskwarrior */ @@ -216,6 +218,16 @@ class TaskManager $errors[] = "A recurring task must also have a 'due' date."; } + if (!preg_match(static::PATTERN, $task->getProject())) { + $errors[] = sprintf("Project with the name '%s' is not allowed", $task->getProject()); + } + + foreach ($task->getTags() as $tag) { + if (!preg_match(static::PATTERN, $tag)) { + $errors[] = sprintf("Tag with the name '%s' is not allowed", $tag); + } + } + return $errors; } diff --git a/tests/TaskManagerTest.php b/tests/TaskManagerTest.php index eca749d..740770a 100644 --- a/tests/TaskManagerTest.php +++ b/tests/TaskManagerTest.php @@ -549,6 +549,18 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase $this->assertCount(1,$this->taskManager->filterPending('+später')); } + public function testTagNameNotAllowed() + { + $this->setExpectedException('DavidBadura\Taskwarrior\Exception\TaskwarriorException', + "Tag with the name 'foo-bar' is not allowed"); + + $task1 = new Task(); + $task1->setDescription('foo1'); + $task1->addTag('foo-bar'); + + $this->taskManager->save($task1); + } + public function testWait() { $task1 = new Task();