-
-
Notifications
You must be signed in to change notification settings - Fork 490
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
Add defensive coding in posts per page sniff #2392
Conversation
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.
@dingo-d Thanks for trying to take this one on.
Unfortunately, this is not the correct fix.
Think of it this way: if the $val
is an empty string will a numeric comparison ever have any value ? No, it won't.
So instead, this sniff needs to do a check of $stripped_val
against an empty string, straight after the quotes have been stripped and the function should bow out and return false
in that case.
The patch also needs a few tests to cover the change - the test from the report + a test with an empty string passed to posts_per_page
when set as an array.
Probably also a good thing to add a similar test to the DB/SlowQuery
sniff, which doesn't have the same issue due to the difference in code for callback
, but still.
$query = 'foo=bar&meta_key=&meta_value=bar';
38f2834
to
b2d41a3
Compare
Fixed the PR according to the comments, much appreciated, should have taken a better look into the sniff. For the |
The |
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.
LGTM ✅
Note: of the tests, only the tests on line 128 and 134 would trigger the notice previously. All the same, the additional tests do test the extra added logic, so 👍🏻 .
Would be nice to see the extra test for SlowQuery
added as well, but happy to ship this as is.
@dingo-d P.S.: feel free to squash the commits. |
Do you want me to squash all into one, or separate the test ones from the sniff changes ones? |
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.
Do you want me to squash all into one, or separate the test ones from the sniff changes ones?
No, this should be one commit. The tests belong with the functional change, so should be included in the same commit (makes life a lot easier when checking history).
535652b
to
f9c2e8f
Compare
The posts per page sniff should bail out early if empty string is passed as a value. The tests were added for both posts per page sniff and slow db query sniff, to check if empty string is passed as a value. In the case of SlowDBQuery the sniff should flag cases where there is and isn't a value passed, as that sniff will always flag whenever meta_key and meta_value are used in a query.
f9c2e8f
to
25033a6
Compare
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.
✅
This will prevent the undefined offset internal error.
Closes #2390