WordPress.org

Make WordPress Core

Ticket #29589: 29589.patch

File 29589.patch, 2.2 KB (added by boonebgorges, 7 years ago)
  • src/wp-includes/taxonomy.php

    diff --git src/wp-includes/taxonomy.php src/wp-includes/taxonomy.php
    index 5846844..4175481 100644
    function get_terms( $taxonomies, $args = '' ) { 
    16551655 * @param int|string $term The term to check
    16561656 * @param string $taxonomy The taxonomy name to use
    16571657 * @param int $parent ID of parent term under which to confine the exists search.
    1658  * @return mixed Returns 0 if the term does not exist. Returns the term ID if no taxonomy is specified
    1659  *               and the term ID exists. Returns an array of the term ID and the term taxonomy ID
    1660  *               if the taxonomy is specified and the pairing exists.
     1658 * @return mixed Returns null if the term does not exist. Returns the term ID
     1659 *               if no taxonomy is specified and the term ID exists. Returns
     1660 *               an array of the term ID and the term taxonomy ID if the
     1661 *               taxonomy is specified and the pairing exists.
    16611662 */
    16621663function term_exists($term, $taxonomy = '', $parent = 0) {
    16631664        global $wpdb;
    function term_exists($term, $taxonomy = '', $parent = 0) { 
    16761677        }
    16771678
    16781679        $term = trim( wp_unslash( $term ) );
    1679 
    1680         if ( '' === $slug = sanitize_title($term) )
    1681                 return 0;
     1680        $slug = sanitize_title( $term );
    16821681
    16831682        $where = 't.slug = %s';
    16841683        $else_where = 't.name = %s';
  • tests/phpunit/tests/term.php

    diff --git tests/phpunit/tests/term.php tests/phpunit/tests/term.php
    index 2576157..9ad8969 100644
    class Tests_Term extends WP_UnitTestCase { 
    112112        }
    113113
    114114        public function test_term_exists_term_trimmed_to_empty_string() {
    115                 $this->assertSame( 0, term_exists( '   ' ) );
     115                $this->assertNull( term_exists( '   ' ) );
     116        }
     117
     118        /**
     119         * @ticket 29589
     120         */
     121        public function test_term_exists_existing_term_that_sanitizes_to_empty() {
     122                wp_insert_term( '//', 'category' );
     123                $this->assertNotEmpty( term_exists( '//' ) );
     124                $this->assertNotEmpty( term_exists( '//', 'category' ) );
     125
     126                wp_insert_term( '>>', 'category' );
     127                $this->assertNotEmpty( term_exists( '>>' ) );
     128                $this->assertNotEmpty( term_exists( '>>', 'category' ) );
    116129        }
    117130
    118131        public function test_term_exists_taxonomy_nonempty_parent_nonempty_match_slug() {