From afa1e2079d5531d8be82fd7f44a62bd3f5b13f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Baptiste=20Clavi=C3=A9?= Date: Thu, 8 Jan 2015 15:00:11 +0100 Subject: [PATCH] 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 --- src/Symfony/Component/Console/Input/ArgvInput.php | 6 ++++-- src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Console/Input/ArgvInput.php b/src/Symfony/Component/Console/Input/ArgvInput.php index 7234f75608..f5cc5d136b 100644 --- a/src/Symfony/Component/Console/Input/ArgvInput.php +++ b/src/Symfony/Component/Console/Input/ArgvInput.php @@ -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, '=')) { diff --git a/src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php b/src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php index 451b108179..bdbe3543b8 100644 --- a/src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php +++ b/src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php @@ -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'), ); }