-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
greg-1-anderson
wants to merge
4
commits into
symfony:2.7
from
greg-1-anderson:guard-invalid-hasparamopt
Closed
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e3fb107
Fixes #26136: Avoid emitting warning when hasParameterOption / getPar…
greg-1-anderson 242e6fc
Use a !== yoda-conditional instead of 'empty' to match Symfony code s…
greg-1-anderson 47d0e93
Test to ensure that getParameterOption / hasParameterOption throws no…
greg-1-anderson 2b41dbb
Fix type of expected value in getParameterOption test.
greg-1-anderson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
8000
|
@@ -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)) { | ||
return true; | ||
} | ||
} | ||
|
@@ -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)); | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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 passing0
et. al. to strpos would also be problematic.I'll go ahead and make this change later today for the sake of style, though.
There was a problem hiding this comment.
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/vuoiAUse
'' !== $value
insteadThere was a problem hiding this comment.
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 pass0
ornull
.That said, I will follow the provided advice for the sake of style, although it makes the guard less effective.