Fixes ArgvInput's argument getter with empty tokens

If an empty token is provided (from automated tools, or on purpose when
running a command), the argument getter was not checking the other
tokens, as '' == false in php, which is the stop condition of the while
loop in this method.

This method should now rely on the count of tokens rather than the value
of the return of array_shift
This commit is contained in:
Baptiste Clavié 2015-01-08 15:00:11 +01:00 committed by Fabien Potencier
parent b08115bd63
commit afa1e2079d
2 changed files with 5 additions and 2 deletions

View File

@ -309,9 +309,11 @@ class ArgvInput extends Input
public function getParameterOption($values, $default = false)
{
$values = (array) $values;
$tokens = $this->tokens;
while ($token = array_shift($tokens)) {
while (0 < count($tokens)) {
$token = array_shift($tokens);
foreach ($values as $value) {
if ($token === $value || 0 === strpos($token, $value.'=')) {
if (false !== $pos = strpos($token, '=')) {

View File

@ -304,6 +304,7 @@ class ArgvInputTest extends \PHPUnit_Framework_TestCase
array(array('app/console', 'foo:bar', '-e', 'dev'), array('-e', '--env'), 'dev'),
array(array('app/console', 'foo:bar', '--env=dev'), array('-e', '--env'), 'dev'),
array(array('app/console', 'foo:bar', '--env=dev', '--en=1'), array('--en'), '1'),
array(array('app/console', 'foo:bar', '--env=dev', '', '--en=1'), array('--en'), '1'),
);
}