Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

Escape command, options and line builder in Processus #42

Open
Hywan opened this issue Feb 27, 2015 · 0 comments
Open

Escape command, options and line builder in Processus #42

Hywan opened this issue Feb 27, 2015 · 0 comments

Comments

@Hywan
Copy link
Member

Hywan commented Feb 27, 2015

Hello :-),

Hoa\Console\Processus automatically escape command and options. Moreover, when building the command line, it adds a = between the option name and the option value. See

Console/Processus.php

Lines 963 to 1035 in 26092d3

/**
* Set command name.
*
* @access protected
* @param string $command Command name.
* @return string
*/
protected function setCommand ( $command ) {
$old = $this->_command;
$this->_command = escapeshellcmd($command);
return $old;
}
/**
* Get command name.
*
* @access public
* @return string
*/
public function getCommand ( ) {
return $this->_command;
}
/**
* Set command options.
*
* @access protected
* @param array $options Options (option => value, or input).
* @return array
*/
protected function setOptions ( Array $options ) {
foreach($options as &$option)
$option = escapeshellarg($option);
$old = $this->_options;
$this->_options = $options;
return $old;
}
/**
* Get options.
*
* @access public
* @return array
*/
public function getOptions ( ) {
return $this->_options;
}
/**
* Get command-line.
*
* @access public
* @return string
*/
public function getCommandLine ( ) {
$out = $this->getCommand();
foreach($this->getOptions() as $key => $value)
if(!is_int($key))
$out .= ' ' . $key . '=' . $value;
else
$out .= ' ' . $value;
return $out;
}
.

In some case, this behavior is not desired. For instance, with atoum, when we build the command, we don't use the $options because = will be inserted and atoum does not support them. The solution is to pass the whole command line in $command, with the options. It's fine, this is how to deal with it.
However, because Processus automatically escape the command, sometimes, it is not what we expect because escaping can create invalid command. Example: --filter 'class = "foo"' becomes --filter 'class = \"foo\"'.

2 solutions:

  1. we tell the users of this behavior in the documentation and we advice to extend Processus and override the setCommand method,
  2. we add one or more arguments in the constructor to disable the escaping.

Thoughts? /cc @hoaproject/hoackers


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

1 participant