Query: Ignore search terms consisting of a single dash.

Due to the "exclude" support added in WP 4.4, single dashes were being
converted to "NOT LIKE '%%'" clauses, causing all searches to fail.

Props RomSocial, swissspidy.
Fixes #36195.

git-svn-id: https://develop.svn.wordpress.org/trunk@36989 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2016-03-14 14:11:16 +00:00
parent 0fdf0d4566
commit 9f05bf8ed9
2 changed files with 27 additions and 2 deletions

View File

@ -2194,8 +2194,8 @@ class WP_Query {
else
$term = trim( $term, "\"' " );
// Avoid single A-Z.
if ( ! $term || ( 1 === strlen( $term ) && preg_match( '/^[a-z]$/i', $term ) ) )
// Avoid single A-Z and single dashes.
if ( ! $term || ( 1 === strlen( $term ) && preg_match( '/^[a-z\-]$/i', $term ) ) )
continue;
if ( in_array( call_user_func( $strtolower, $term ), $stopwords, true ) )

View File

@ -126,6 +126,31 @@ class Tests_Query_Search extends WP_UnitTestCase {
$this->assertEqualSets( array( $p3 ), $q->posts );
}
/**
* @ticket 36195
*/
public function test_s_should_not_exclude_for_dashes_between_words() {
$p1 = self::factory()->post->create( array(
'post_status' => 'publish',
'post_content' => 'This post has foo but also bar',
) );
$p2 = self::factory()->post->create( array(
'post_status' => 'publish',
'post_content' => 'This post has only bar',
) );
$p3 = self::factory()->post->create( array(
'post_status' => 'publish',
'post_content' => 'This post has only foo - bar',
) );
$q = new WP_Query( array(
's' => 'foo - bar',
'fields' => 'ids',
) );
$this->assertEqualSets( array( $p1, $p3 ), $q->posts );
}
/**
* @ticket 35361
*/