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

Escape command, options and line builder in Processus #42

@Hywan

Description

@Hywan

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions