Make WordPress Core

Ticket #44296: 44296_1.patch

File 44296_1.patch, 1.7 KB (added by ryotsun, 6 years ago)
  • src/wp-includes/class-wp-query.php

     
    13081308                }
    13091309                // there are no line breaks in <input /> fields
    13101310                $q['s']                  = str_replace( array( "\r", "\n" ), '', $q['s'] );
     1311                // replace double-width space to half-width.
     1312                $q['s']                  = mb_convert_kana($q['s'], 's');
    13111313                $q['search_terms_count'] = 1;
    13121314                if ( ! empty( $q['sentence'] ) ) {
    13131315                        $q['search_terms'] = array( $q['s'] );
  • tests/phpunit/tests/query/search.php

     
    6060                $this->assertEquals( array( 'search', 'term' ), $query->get( 'search_terms' ) );
    6161        }
    6262
     63        /**
     64         * Check if double-width space will be recognized as a separator
     65         */
     66        function test_filter_stopwords_including_double_width_space() {
     67                $terms = 'This is a search term';
     68                add_filter( 'wp_search_stopwords', array( $this, 'filter_wp_search_stopwords' ) );
     69                $query = new WP_Query( array( 's' => $terms ) );
     70                remove_filter( 'wp_search_stopwords', array( $this, 'filter_wp_search_stopwords' ) );
     71
     72                $this->assertNotEquals( explode( ' ', $terms ), $query->get( 'search_terms' ) );
     73                $this->assertEquals( 5, $query->get( 'search_terms_count') );
     74                $this->assertEquals( array( 'This', 'is', 'search', 'term' ), $query->get( 'search_terms' ) );
     75        }
     76
    6377        function test_filter_stopwords() {
    6478                $terms = 'This is a search term';
    6579                add_filter( 'wp_search_stopwords', array( $this, 'filter_wp_search_stopwords' ) );