diff --git a/src/Taskwarrior.php b/src/Taskwarrior.php index ad72506..0c380b7 100644 --- a/src/Taskwarrior.php +++ b/src/Taskwarrior.php @@ -117,7 +117,7 @@ class Taskwarrior $file = tempnam(sys_get_temp_dir(), 'task') . '.json'; $fs->dumpFile($file, $json); - $output = $this->command('import', $file); + $output = $this->command('import', null, [$file]); $fs->remove($file); @@ -153,11 +153,7 @@ class Taskwarrior } if ($filter) { - if (strpos($filter, '(') !== false) { - $parts[] = "'" . $filter . "'"; - } else { - $parts[] = $filter; - } + $parts[] = "( " . $filter . ' )'; } $parts[] = $command; @@ -166,7 +162,7 @@ class Taskwarrior $parts[] = $param; } - $process = new Process(implode(' ', $parts)); + $process = new Process($this->createCommandLine($parts)); $process->run(); if (!$process->isSuccessful()) { @@ -181,11 +177,11 @@ class Taskwarrior */ public function version() { - if ($this->version) { - return $this->version; + if (!$this->version) { + $this->version = trim($this->command('_version')); } - return $this->version = trim($this->command('_version')); + return $this->version; } /** @@ -261,6 +257,19 @@ class Taskwarrior return array_filter(explode("\n", $string), 'strlen'); } + /** + * @param array $parts + * @return string + */ + private function createCommandLine(array $parts) + { + $parts = array_map(function($part) { + return "'" . str_replace("'", "'\\''", $part) . "'"; + }, $parts); + + return implode(' ', $parts); + } + /** * @param string $string * @return string|null diff --git a/tests/TaskManagerTest.php b/tests/TaskManagerTest.php index b354b9c..2b513bf 100644 --- a/tests/TaskManagerTest.php +++ b/tests/TaskManagerTest.php @@ -69,6 +69,32 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase $this->assertEquals($task, $result); } + public function testUrlInDescription() + { + $task = new Task(); + $task->setDescription('hier http://google.de '); + + $this->taskManager->save($task); + $this->taskManager->clear(); + + $result = $this->taskManager->find($task->getUuid()); + + $this->assertEquals('hier http://google.de ', $result->getDescription()); + } + + public function testQuoteInDescription() + { + $task = new Task(); + $task->setDescription(" test ' foo "); + + $this->taskManager->save($task); + $this->taskManager->clear(); + + $result = $this->taskManager->find($task->getUuid()); + + $this->assertEquals(" test ' foo ", $result->getDescription()); + } + public function testSaveTaskWithoutDescription() { $this->setExpectedException('DavidBadura\Taskwarrior\Exception\TaskwarriorException');