Fixes #26136: Avoid emitting warning in hasParameterOption()

This commit is contained in:
Greg Anderson 2018-02-12 14:05:44 -08:00 committed by Fabien Potencier
parent aa3a04ad28
commit b32fdf1ca3
2 changed files with 17 additions and 2 deletions

View File

@ -283,7 +283,7 @@ class ArgvInput extends Input
// For long options, test for '--option=' at beginning
// For short options, test for '-o' at beginning
$leading = 0 === strpos($value, '--') ? $value.'=' : $value;
if ($token === $value || 0 === strpos($token, $leading)) {
if ($token === $value || '' !== $leading && 0 === strpos($token, $leading)) {
return true;
}
}
@ -311,7 +311,7 @@ class ArgvInput extends Input
// For long options, test for '--option=' at beginning
// For short options, test for '-o' at beginning
$leading = 0 === strpos($value, '--') ? $value.'=' : $value;
if (0 === strpos($token, $leading)) {
if ('' !== $leading && 0 === strpos($token, $leading)) {
return substr($token, strlen($leading));
}
}

View File

@ -337,6 +337,21 @@ class ArgvInputTest extends TestCase
$this->assertFalse($input->hasParameterOption('-fh'), '->hasParameterOption() returns true if the given short option is in the raw input');
}
public function testNoWarningOnInvalidParameterOption()
{
$input = new ArgvInput(array('cli.php', '-edev'));
// Control.
$this->assertTrue($input->hasParameterOption(array('-e', '')));
// No warning is thrown if https://github.com/symfony/symfony/pull/26156 is fixed
$this->assertFalse($input->hasParameterOption(array('-m', '')));
// Control.
$this->assertEquals('dev', $input->getParameterOption(array('-e', '')));
// No warning is thrown if https://github.com/symfony/symfony/pull/26156 is fixed
$this->assertFalse($input->getParameterOption(array('-m', '')));
}
public function testToString()
{
$input = new ArgvInput(array('cli.php', '-f', 'foo'));