Make WordPress Core

Ticket #36195: 36195.diff

File 36195.diff, 1.7 KB (added by swissspidy, 10 years ago)
  • src/wp-includes/query.php

    diff --git src/wp-includes/query.php src/wp-includes/query.php
    index 4b3e1e4..12debb7 100644
    class WP_Query { 
    21942194                        else
    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 ) || '-' === $term ) )
    21992199                                continue;
    22002200
    22012201                        if ( in_array( call_user_func( $strtolower, $term ), $stopwords, true ) )
  • tests/phpunit/tests/query/search.php

    diff --git tests/phpunit/tests/query/search.php tests/phpunit/tests/query/search.php
    index 35f734b..7f7db19 100644
    class Tests_Query_Search extends WP_UnitTestCase { 
    127127        }
    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         */
    132157        public function test_search_orderby_should_be_empty_when_search_string_is_longer_than_6_words_and_exclusion_operator_is_used() {