Skip to content

Commit 54ad2d7

Browse files
authored
Merge pull request #2392 from WordPress/hotfix/2390-internal-error
Add defensive coding in posts per page sniff
2 parents e6b3033 + 25033a6 commit 54ad2d7

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

WordPress/Sniffs/WP/PostsPerPageSniff.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ public function getGroups() {
6767
public function callback( $key, $val, $line, $group ) {
6868
$stripped_val = TextStrings::stripQuotes( $val );
6969

70+
if ( '' === $stripped_val ) {
71+
return false;
72+
}
73+
7074
if ( $val !== $stripped_val ) {
7175
// The value was a text string. For text strings, we only accept purely numeric values.
7276
if ( preg_match( '`^[0-9]+$`', $stripped_val ) !== 1 ) {

WordPress/Tests/DB/SlowDBQueryUnitTest.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ $query = 'foo=bar&meta_key=foo&meta_value=bar';
2121
if ( ! isset( $widget['params'][0] ) ) {
2222
$widget['params'][0] = array();
2323
}
24+
25+
$query = 'foo=bar&meta_key=&meta_value=bar';
26+
$query = 'foo=bar&meta_key=foo&meta_value=';
27+
$query = 'foo=bar&meta_key=&meta_value=';

WordPress/Tests/DB/SlowDBQueryUnitTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public function getWarningList() {
4444
15 => 1,
4545
16 => 1,
4646
19 => 2,
47+
25 => 2,
48+
26 => 2,
49+
27 => 2,
4750
);
4851
}
4952
}

WordPress/Tests/WP/PostsPerPageUnitTest.inc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,17 @@ $args = array(
124124
'posts_per_page' => 75.0, // OK (75).
125125
'posts_per_page' => 150.000, // Bad (150).
126126
);
127+
128+
$query = 'posts_per_page=' . (int) $_POST['limit']; // OK.
129+
130+
$args = array(
131+
'posts_per_page' => '', // OK.
132+
);
133+
134+
_query_posts( 'nopaging=true&posts_per_page=' ); // OK.
135+
136+
$query_args['posts_per_page'] = ''; // OK.
137+
138+
$query_args[
139+
'posts_per_page'
140+
] = ''; // OK.

0 commit comments

Comments
 (0)