WordPress.org

Make WordPress Core

Changeset 31392


Ignore:
Timestamp:
02/09/2015 10:53:40 PM (7 years ago)
Author:
boonebgorges
Message:

Don't parse empty 'tax_input' keys in edit_post().

This fixes a bug introduced in [31359] where saving a tax_input that contained
only whitespace would result in a random tag being erroneously added to the
post.

See #30615.

Location:
trunk
Files:
2 edited

Legend:

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

    r31359 r31392  
    338338            $clean_terms = array();
    339339            foreach ( $terms as $term ) {
     340                // Empty terms are invalid input.
     341                if ( empty( $term ) ) {
     342                    continue;
     343                }
     344
    340345                $_term = get_terms( $taxonomy, array(
    341346                    'name' => $term,
  • trunk/tests/phpunit/tests/admin/includesPost.php

    r31359 r31392  
    177177
    178178    /**
     179     * @ticket 30615
     180     */
     181    public function test_edit_post_should_not_create_terms_for_an_empty_tag_input_field() {
     182        $u = $this->factory->user->create( array( 'role' => 'editor' ) );
     183        wp_set_current_user( $u );
     184
     185        register_taxonomy( 'wptests_tax', array( 'post' ) );
     186        $t1 = $this->factory->term->create( array(
     187            'taxonomy' => 'wptests_tax',
     188            'name' => 'foo',
     189            'slug' => 'bar',
     190        ) );
     191
     192        $p = $this->factory->post->create();
     193
     194        $post_data = array(
     195            'post_ID' => $p,
     196            'tax_input' => array(
     197                'wptests_tax' => ' ',
     198            ),
     199        );
     200
     201        edit_post( $post_data );
     202
     203        $found = wp_get_post_terms( $p, 'wptests_tax' );
     204
     205        $this->assertEmpty( $found );
     206    }
     207
     208    /**
    179209     * @ticket 27792
    180210     */
Note: See TracChangeset for help on using the changeset viewer.