Make WordPress Core

Changeset 36989


Ignore:
Timestamp:
03/14/2016 02:11:16 PM (8 years ago)
Author:
boonebgorges
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/query.php

    r36699 r36989  
    21952195                $term = trim( $term, "\"' " );
    21962196
    2197             // Avoid single A-Z.
    2198             if ( ! $term || ( 1 === strlen( $term ) && preg_match( '/^[a-z]$/i', $term ) ) )
     2197            // Avoid single A-Z and single dashes.
     2198            if ( ! $term || ( 1 === strlen( $term ) && preg_match( '/^[a-z\-]$/i', $term ) ) )
    21992199                continue;
    22002200
  • trunk/tests/phpunit/tests/query/search.php

    r36647 r36989  
    128128
    129129    /**
     130     * @ticket 36195
     131     */
     132    public function test_s_should_not_exclude_for_dashes_between_words() {
     133        $p1 = self::factory()->post->create( array(
     134            'post_status' => 'publish',
     135            'post_content' => 'This post has foo but also bar',
     136        ) );
     137        $p2 = self::factory()->post->create( array(
     138            'post_status' => 'publish',
     139            'post_content' => 'This post has only bar',
     140        ) );
     141        $p3 = self::factory()->post->create( array(
     142            'post_status' => 'publish',
     143            'post_content' => 'This post has only foo - bar',
     144        ) );
     145
     146        $q = new WP_Query( array(
     147            's' => 'foo - bar',
     148            'fields' => 'ids',
     149        ) );
     150
     151        $this->assertEqualSets( array( $p1, $p3 ), $q->posts );
     152    }
     153
     154    /**
    130155     * @ticket 35361
    131156     */
Note: See TracChangeset for help on using the changeset viewer.