bug #13332 [Console] ArgvInput and empty tokens (Taluu)
This PR was submitted for the 2.5 branch but it was merged into the 2.3 branch instead (closes #13332).
Discussion
----------
[Console] ArgvInput and empty tokens
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | ~
| License | MIT
| Doc PR | ~
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 on the value of the return of `array_shift`
If the fix is removed on the ArgvInput, the test `testGetParameterOptionEqualSign` should fail, as it shows why this fix is needed (last line of its provider `provideGetParameterOptionValues`)
This is relevant on 2.4+, but as 2.4 has stopped expecting bug fixes since july 2014, I based this PR on 2.5+. So this should be merged in 2.5, 2.6, 2.7 and possibly on master. This should also be cherry-pickable on 2.3 (as it is the current LTS)
Commits
-------
afa1e20
Fixes ArgvInput's argument getter with empty tokens
This commit is contained in:
commit
56f315495c
@ -309,9 +309,11 @@ class ArgvInput extends Input
|
|||||||
public function getParameterOption($values, $default = false)
|
public function getParameterOption($values, $default = false)
|
||||||
{
|
{
|
||||||
$values = (array) $values;
|
$values = (array) $values;
|
||||||
|
|
||||||
$tokens = $this->tokens;
|
$tokens = $this->tokens;
|
||||||
while ($token = array_shift($tokens)) {
|
|
||||||
|
while (0 < count($tokens)) {
|
||||||
|
$token = array_shift($tokens);
|
||||||
|
|
||||||
foreach ($values as $value) {
|
foreach ($values as $value) {
|
||||||
if ($token === $value || 0 === strpos($token, $value.'=')) {
|
if ($token === $value || 0 === strpos($token, $value.'=')) {
|
||||||
if (false !== $pos = strpos($token, '=')) {
|
if (false !== $pos = strpos($token, '=')) {
|
||||||
|
@ -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', '-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'), 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'),
|
||||||
|
array(array('app/console', 'foo:bar', '--env=dev', '', '--en=1'), array('--en'), '1'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user