Skip to content

Commit afa1e20

Browse files
Taluufabpot
authored andcommitted
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
1 parent b08115b commit afa1e20

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/Symfony/Component/Console/Input/ArgvInput.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,11 @@ public function hasParameterOption($values)
309309
public function getParameterOption($values, $default = false)
310310
{
311311
$values = (array) $values;
312-
313312
$tokens = $this->tokens;
314-
while ($token = array_shift($tokens)) {
313+
314+
while (0 < count($tokens)) {
315+
$token = array_shift($tokens);
316+
315317
foreach ($values as $value) {
316318
if ($token === $value || 0 === strpos($token, $value.'=')) {
317319
if (false !== $pos = strpos($token, '=')) {

src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ public function provideGetParameterOptionValues()
304304
array(array('app/console', 'foo:bar', '-e', 'dev'), array('-e', '--env'), 'dev'),
305305
array(array('app/console', 'foo:bar', '--env=dev'), array('-e', '--env'), 'dev'),
306306
array(array('app/console', 'foo:bar', '--env=dev', '--en=1'), array('--en'), '1'),
307+
array(array('app/console', 'foo:bar', '--env=dev', '', '--en=1'), array('--en'), '1'),
307308
);
308309
}
309310

0 commit comments

Comments
 (0)