Fixes #26136: Avoid emitting warning in hasParameterOption()
This commit is contained in:
parent
aa3a04ad28
commit
b32fdf1ca3
@ -283,7 +283,7 @@ class ArgvInput extends Input
|
|||||||
// For long options, test for '--option=' at beginning
|
// For long options, test for '--option=' at beginning
|
||||||
// For short options, test for '-o' at beginning
|
// For short options, test for '-o' at beginning
|
||||||
$leading = 0 === strpos($value, '--') ? $value.'=' : $value;
|
$leading = 0 === strpos($value, '--') ? $value.'=' : $value;
|
||||||
if ($token === $value || 0 === strpos($token, $leading)) {
|
if ($token === $value || '' !== $leading && 0 === strpos($token, $leading)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -311,7 +311,7 @@ class ArgvInput extends Input
|
|||||||
// For long options, test for '--option=' at beginning
|
// For long options, test for '--option=' at beginning
|
||||||
// For short options, test for '-o' at beginning
|
// For short options, test for '-o' at beginning
|
||||||
$leading = 0 === strpos($value, '--') ? $value.'=' : $value;
|
$leading = 0 === strpos($value, '--') ? $value.'=' : $value;
|
||||||
if (0 === strpos($token, $leading)) {
|
if ('' !== $leading && 0 === strpos($token, $leading)) {
|
||||||
return substr($token, strlen($leading));
|
return substr($token, strlen($leading));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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');
|
$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()
|
public function testToString()
|
||||||
{
|
{
|
||||||
$input = new ArgvInput(array('cli.php', '-f', 'foo'));
|
$input = new ArgvInput(array('cli.php', '-f', 'foo'));
|
||||||
|
Reference in New Issue
Block a user