summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--it.class11
-rwxr-xr-xtests/exec.t1
2 files changed, 7 insertions, 5 deletions
diff --git a/it.class b/it.class
index 1104894..9463d41 100644
--- a/it.class
+++ b/it.class
@@ -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");