Skip to content
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

PreGetPosts: improve the isEarlyMainQueryCheck() method #565

Merged
merged 2 commits into from
Jul 28, 2020

Conversation

jrfnl
Copy link
Collaborator

@jrfnl jrfnl commented Jul 28, 2020

This adds a unit test which results in the error as reported in issue #499 and fixes the error properly.

The error was caused by the presumption in the code that if a check for is_main_query has a scope condition which is a closure, that the closure is the callback in the hook function call and that therefore the outer parenthesis (those of the function call) should be disgarded and the next parenthesis will be the ones for the if statement which will always have a scope opener and closer.

Now read the above sentence again and count the number of assumptions in that statement ;-)

Either way, the fix I've now added should stabilize this part of the code.

Fixes #499


[Edit] I've added a second commit to the code after seeing the actual code which was triggering the error.


PreGetPosts: improve the isEarlyMainQueryCheck() method [2]

This adds a second unit test which is based on the actual code which originally triggered the error.

The error was caused by the code in question using inline control structures (without braces) for the early main query check.

After the previous fix, that code would now throw a false positive.

I've fixed this now by adding an additional check for a return statement straight after the parenthesis closer of the if() statement.

This adds a unit test which results in the error as reported in issue 499 and fixes the error properly.

The error was caused by the presumption in the code that if an a check for `is_main_query` has a scope condition which is a `closure`, that the `closure` is the callback in the hook function call and that therefore the outer parenthesis (those of the function call) should be disgarded and the next parenthesis will be the ones for the `if` statement which will always have a scope opener and closer.

Now read the above sentence again and count the number of assumptions in that statement ;-)

Either way, the fix I've now added should stabilize this part of the code.

Fixes 499
@jrfnl jrfnl force-pushed the fix/499-pregetposts-undefined-index-notice branch from 8845433 to 82d1232 Compare July 28, 2020 14:36
This adds a second unit test which is based on the actual code which originally triggered the error.

The error was caused by the code in question using inline control structures (without braces) for the early main query check.

After the previous fix, that code would now throw a false positive.

I've fixed this now by adding an additional check for a `return` statement straight after the parenthesis closer of the `if()` statement.

Fixes 499
@GaryJones GaryJones merged commit 45fd0d4 into develop Jul 28, 2020
@GaryJones GaryJones deleted the fix/499-pregetposts-undefined-index-notice branch July 28, 2020 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Internal Exception // Undefined index: scope_opener PreGetPostsSniff.php on line 314
2 participants