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
Changes from 1 commit
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
8000 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 || !empty($leading) && 0 === strpos($token, $leading)) {
Copy link
Member

Choose a reason for hiding this comment

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

Let's try to avoid using empty() as it catches too many cases, like0 and others.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason for this conditional is to avoid values of $leading that cause problems for strpos; therefore, I think that empty is entirely appropriate, since passing 0 et. al. to strpos would also be problematic.

I'll go ahead and make this change later today for the sake of style, though.

Copy link
Member

Choose a reason for hiding this comment

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

@greg-1-anderson '0' is empty as well: https://3v4l.org/vuoiA

Use '' !== $value instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stof The point of my comment is that the purpose of adding a conditional here is only to prevent strpos from emitting a warning if the caller of these functions passes a bad value. With !==, we protect only against the empty string, and allow the warning to happen if uses pass 0 or null.

That said, I will follow the provided advice for the sake of style, although it makes the guard less effective.

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 (!empty($leading) && 0 === strpos($token, $leading)) {
return substr($token, strlen($leading));
}
}
Expand Down
0