8000 Fixes #26136: Avoid emitting warning in hasParameterOption() by greg-1-anderson · Pull Request #26156 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Fixes #26136: Avoid emitting warning in hasParameterOption() #26156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Input/ArgvInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public function hasParameterOption($values)
// 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;
}
}
Expand Down Expand Up @@ -311,7 +311,7 @@ public function getParameterOption($values, $default = false)
// 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));
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,21 @@ public function testHasParameterOptionEdgeCasesAndLimitations()
$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->assertEquals('', $input->getParameterOption(array('-m', '')));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it really be an empty string here ? The option is not there, so it should be false AFAICT (this is the drawback of assertEquals: it performs type juggling)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct; that is an error in the test.

}

public function testToString()
{
$input = new ArgvInput(array('cli.php', '-f', 'foo'));
Expand Down
0