-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Query Total: Prevent stricted type fatal errors on post per page. #69508
Conversation
@@ -31,7 +31,7 @@ function render_block_core_query_total( $attributes, $content, $block ) { | |||
} | |||
|
|||
$max_rows = $query_to_use->found_posts; |
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.
Should we also cast this value just to be on the safe side?
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.
I think found_posts
is already set as int on the query object.
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.
I confirmed that found_posts
is always set as int
.
What about $current_page = max( 1, get_query_var( 'paged', 1 ) );
? In particular, I'm worried about get_query_var
as it has a mixed return value.
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
@@ -23,15 +23,15 @@ function render_block_core_query_total( $attributes, $content, $block ) { | |||
$wrapper_attributes = get_block_wrapper_attributes(); | |||
if ( isset( $block->context['query']['inherit'] ) && $block->context['query']['inherit'] ) { | |||
$query_to_use = $wp_query; | |||
$current_page = max( 1, get_query_var( 'paged', 1 ) ); | |||
$current_page = max( 1, (int) get_query_var( 'paged', 1 ) ); |
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 get_query_var
also uses WP_Query::get
under the hood and ``min( 1, '0' )will return
"0"`.
Flaky tests detected in 343bb4c. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/13764560001
|
…9508) Co-authored-by: cbravobernal <cbravobernal@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: gziolo <gziolo@git.wordpress.org>
I just cherry-picked this PR to the wp/6.8 branch to get it included in the next release: 918d0cd |
Why?
Some hostings, with PHP updated versions and strict types, can cause a fatal error if posts_per_page is returning 0 as a string instead of an integer.
$start = ( $current_page - 1 ) * $posts_per_page + 1;
this arithmetical function will cause a Fatal error if $posts_per_page is an string.How?
Forcing it to be a an integer.