fix filter & escaping

This commit is contained in:
DavidBadura
2015-04-23 16:49:41 +00:00
parent 682561a58e
commit d392b5871e
2 changed files with 45 additions and 10 deletions

View File

@@ -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