diff options
author | Urban Müller | 2012-11-29 14:18:19 +0000 |
---|---|---|
committer | Urban Müller | 2012-11-29 14:18:19 +0000 |
commit | ecea76684314768e352deffbe9ffadd679cbcba7 (patch) | |
tree | aa900a5e87476dcd0d5792bbeb0d696d352195c7 | |
parent | 28d622fd07ed7d962f6827a3e07219e0bde7925e (diff) | |
download | itools-ecea76684314768e352deffbe9ffadd679cbcba7.tar.gz itools-ecea76684314768e352deffbe9ffadd679cbcba7.tar.bz2 itools-ecea76684314768e352deffbe9ffadd679cbcba7.zip |
positional args in it::exec
-rw-r--r-- | it.class | 11 | ||||
-rwxr-xr-x | tests/exec.t | 1 |
2 files changed, 7 insertions, 5 deletions
@@ -482,9 +482,10 @@ static function filter_keys($array, $keys, $p = array()) /** * Construct shell command using it::shell_command, log it, execute it and return output as string. - * Keywords {keyword} are replace a la ET(), {-opts} takes an array and - * inserts options a la it_html attributes (value, true, false or null) - * @param $cmd Format string with {keywords} replace a la ET() + * {keyword} quotes and inserts value from assoc array like ET() + * {0} .. {n} quotes and inserts positional arguments + * {-opts} takes an array and inserts options a la it_html attributes (value, true, false or null) + * @param $cmd Format string with {keywords} a la ET() * @param $values (zero, one or more arrays can be passed) * @return output of command. shell errors not detectable, see error_log in /www/server/logs */ @@ -517,12 +518,12 @@ static function shell_command(/* $cmd, $values1 = array(), ... */) # Merge values into one array foreach ($args as $arg) - $values += (array)$arg; + $values = array_merge($values, (array)$arg); #for escapeshellarg in it::_exec_quotevalue $oldlocale = setlocale(LC_CTYPE, 0); setlocale(LC_CTYPE, 'de_CH'); - foreach (it::match('({(-?)([a-z]\w*)})', $cmd, array('all' => true)) as $tags) + foreach (it::match('({(-?)([a-z0-9]\w*)})', $cmd, array('all' => true)) as $tags) { list($tag, $option, $key) = $tags; $parts = array(); diff --git a/tests/exec.t b/tests/exec.t index 9425420..349f0ed 100755 --- a/tests/exec.t +++ b/tests/exec.t @@ -5,6 +5,7 @@ is(it::exec("echo gna"), "gna\n", "basic exec"); is(it::exec("echo {arg}", array('arg' => 'gna')), "gna\n", "exec with argument"); +is(it::exec("echo {0}", 'gna'), "gna\n", "exec with positional argument"); is(it::shell_command("echo {arg}", array('arg' => 'gna07,-:blah')), "echo gna07,-:blah", "don't quote arguments with only whitelistes characters"); is(it::shell_command("echo {arg}", array('arg' => '2>&1')), "echo '2>&1'", "quote arguments with dangerous characters"); is(it::shell_command("echo {arg}", array('arg' => '')), "echo ''", "quote empty arguments"); |