Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#35513 closed defect (bug) (fixed)

Ignore all falsy arguments for WP_Comment_Query search argument

Reported by: danielbachhuber's profile danielbachhuber Owned by: boonebgorges's profile boonebgorges
Milestone: 4.5 Priority: normal
Severity: normal Version:
Component: Comments Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

WP_Comment_Query currently has a strict check for an empty string. When false or null is passed to search, this results in nonsensical SQL:

[18-Jan-2016 13:18:31 UTC] WP_Comment_Query::__set_state(array(
   'request' => 'SELECT SQL_CALC_FOUND_ROWS wp_comments.comment_ID FROM
   wp_comments JOIN wp_posts ON wp_posts.ID =
   wp_comments.comment_post_ID WHERE ( comment_approved = \'1\' ) AND
   comment_type IN (\'\') AND (comment_author LIKE \'%%\' OR
   comment_author_email LIKE \'%%\' OR comment_author_url LIKE \'%%\' OR
   comment_author_IP LIKE \'%%\' OR comment_content LIKE \'%%\') AND
   wp_posts.post_type IN (\'page\')  ORDER BY
   wp_comments.comment_date_gmt ASC, wp_comments.comment_ID ASC LIMIT
   10',

WP_Comment_Query should ignore all falsy values.

Discovered in https://github.com/WP-API/WP-API/pull/2052

Attachments (1)

35513.1.diff (1.8 KB) - added by danielbachhuber 9 years ago.

Download all attachments as: .zip

Change History (3)

#1 @boonebgorges
9 years ago

Strict comparison was introduced in [15491], at the same time as the search param.

WP_Query handles 's' in a similar way to what's being proposed here. See [36278], [28623].

#2 @boonebgorges
9 years ago

  • Owner set to boonebgorges
  • Resolution set to fixed
  • Status changed from new to closed

In 36345:

Ignore false values of 'search' in WP_Comment_Query.

Props danielbachhuber.
Fixes #35513.

Note: See TracTickets for help on using tickets.