Ignore false values of 'search' in WP_Comment_Query.

Props danielbachhuber.
Fixes #35513.

git-svn-id: https://develop.svn.wordpress.org/trunk@36345 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2016-01-19 02:54:28 +00:00
parent 43da0d3894
commit 1b8e03bd89
2 changed files with 57 additions and 1 deletions

View File

@ -745,7 +745,8 @@ class WP_Comment_Query {
$this->sql_clauses['where']['user_id'] = $wpdb->prepare( 'user_id = %d', $this->query_vars['user_id'] );
}
if ( '' !== $this->query_vars['search'] ) {
// Falsy search strings are ignored.
if ( strlen( $this->query_vars['search'] ) ) {
$search_sql = $this->get_search_sql(
$this->query_vars['search'],
array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content' )

View File

@ -1179,6 +1179,61 @@ class Tests_Comment_Query extends WP_UnitTestCase {
$this->assertEqualSets( array( $c1, $c2, $c3, $c4, $c5 ), $found );
}
/**
* @ticket 35513
*/
public function test_search_false_should_be_ignored() {
$q = new WP_Comment_Query();
$q->query( array(
'search' => false,
) );
$this->assertNotContains( "comment_author LIKE", $q->request );
}
/**
* @ticket 35513
*/
public function test_search_null_should_be_ignored() {
$q = new WP_Comment_Query();
$q->query( array(
'search' => null,
) );
$this->assertNotContains( "comment_author LIKE", $q->request );
}
/**
* @ticket 35513
*/
public function test_search_empty_string_should_be_ignored() {
$q = new WP_Comment_Query();
$q->query( array(
'search' => false,
) );
$this->assertNotContains( "comment_author LIKE", $q->request );
}
/**
* @ticket 35513
*/
public function test_search_int_0_should_not_be_ignored() {
$q = new WP_Comment_Query();
$q->query( array(
'search' => 0,
) );
$this->assertContains( "comment_author LIKE '%0%'", $q->request );
}
/**
* @ticket 35513
*/
public function test_search_string_0_should_not_be_ignored() {
$q = new WP_Comment_Query();
$q->query( array(
'search' => '0',
) );
$this->assertContains( "comment_author LIKE '%0%'", $q->request );
}
public function test_orderby_default() {
global $wpdb;