Make WordPress Core

Ticket #32248: 32248.diff

File 32248.diff, 1.9 KB (added by boonebgorges, 8 years ago)
  • src/wp-includes/taxonomy.php

    diff --git src/wp-includes/taxonomy.php src/wp-includes/taxonomy.php
    index 6760ffe..2f46b2e 100644
    function get_terms( $taxonomies, $args = '' ) { 
    18421842        }
    18431843
    18441844        if ( ! empty( $args['name'] ) ) {
    1845                 if ( is_array( $args['name'] ) ) {
    1846                         $name = array_map( 'sanitize_text_field', $args['name'] );
    1847                         $where .= " AND t.name IN ('" . implode( "', '", array_map( 'esc_sql', $name ) ) . "')";
    1848                 } else {
    1849                         $name = sanitize_text_field( $args['name'] );
    1850                         $where .= $wpdb->prepare( " AND t.name = %s", $name );
     1845                $names = (array) $args['name'];
     1846                foreach ( $names as &$_name ) {
     1847                        $_name = sanitize_term_field( 'name', $_name, 0, reset( $taxonomies ), 'db' );
    18511848                }
     1849
     1850                $where .= " AND t.name IN ('" . implode( "', '", array_map( 'esc_sql', $names ) ) . "')";
    18521851        }
    18531852
    18541853        if ( ! empty( $args['slug'] ) ) {
  • tests/phpunit/tests/term/getTerms.php

    diff --git tests/phpunit/tests/term/getTerms.php tests/phpunit/tests/term/getTerms.php
    index 2dbbaff..333e87e 100644
    class Tests_Term_getTerms extends WP_UnitTestCase { 
    541541        }
    542542
    543543        /**
     544         * @ticket 32248
     545         */
     546        public function test_name_should_match_encoded_html_entities() {
     547                register_taxonomy( 'wptests_tax', 'post' );
     548
     549                $t = $this->factory->term->create( array(
     550                        'taxonomy' => 'wptests_tax',
     551                        'name' => 'Foo & Bar',
     552                        'slug' => 'foo-and-bar',
     553                ) );
     554
     555                $found = get_terms( 'wptests_tax', array(
     556                        'hide_empty' => false,
     557                        'fields' => 'ids',
     558                        'name' => 'Foo & Bar',
     559                ) );
     560                $this->assertEqualSets( array( $t ), $found );
     561
     562                // array format.
     563                $found = get_terms( 'wptests_tax', array(
     564                        'hide_empty' => false,
     565                        'fields' => 'ids',
     566                        'name' => array( 'Foo & Bar' ),
     567                ) );
     568                $this->assertEqualSets( array( $t ), $found );
     569        }
     570
     571        /**
    544572         * @ticket 29839
    545573         */
    546574        public function test_childless_should_return_all_terms_for_flat_hierarchy() {