Skip to content

Commit

Permalink
Merge pull request #2392 from WordPress/hotfix/2390-internal-error
Browse files Browse the repository at this point in the history
Add defensive coding in posts per page sniff
  • Loading branch information
jrfnl authored Sep 18, 2023
2 parents e6b3033 + 25033a6 commit 54ad2d7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions WordPress/Sniffs/WP/PostsPerPageSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public function getGroups() {
public function callback( $key, $val, $line, $group ) {
$stripped_val = TextStrings::stripQuotes( $val );

if ( '' === $stripped_val ) {
return false;
}

if ( $val !== $stripped_val ) {
// The value was a text string. For text strings, we only accept purely numeric values.
if ( preg_match( '`^[0-9]+$`', $stripped_val ) !== 1 ) {
Expand Down
4 changes: 4 additions & 0 deletions WordPress/Tests/DB/SlowDBQueryUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ $query = 'foo=bar&meta_key=foo&meta_value=bar';
if ( ! isset( $widget['params'][0] ) ) {
$widget['params'][0] = array();
}

$query = 'foo=bar&meta_key=&meta_value=bar';
$query = 'foo=bar&meta_key=foo&meta_value=';
$query = 'foo=bar&meta_key=&meta_value=';
3 changes: 3 additions & 0 deletions WordPress/Tests/DB/SlowDBQueryUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public function getWarningList() {
15 => 1,
16 => 1,
19 => 2,
25 => 2,
26 => 2,
27 => 2,
);
}
}
14 changes: 14 additions & 0 deletions WordPress/Tests/WP/PostsPerPageUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,17 @@ $args = array(
'posts_per_page' => 75.0, // OK (75).
'posts_per_page' => 150.000, // Bad (150).
);

$query = 'posts_per_page=' . (int) $_POST['limit']; // OK.

$args = array(
'posts_per_page' => '', // OK.
);

_query_posts( 'nopaging=true&posts_per_page=' ); // OK.

$query_args['posts_per_page'] = ''; // OK.

$query_args[
'posts_per_page'
] = ''; // OK.

0 comments on commit 54ad2d7

Please sign in to comment.