Make WordPress Core

Changeset 30031


Ignore:
Timestamp:
10/26/2014 10:56:36 PM (10 years ago)
Author:
boonebgorges
Message:

Improve WP_Tax_Query param sanitization for empty strings.

When an empty string is passed as one of the clauses in the $tax_query
parameter, it should be discarded rather than parsed as a first-order clause.

Props tmtrademark.
Fixes #30117.

Location:
trunk
Files:
2 edited

Legend:

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

    r29945 r30031  
    833833     */
    834834    protected static function is_first_order_clause( $query ) {
    835         return empty( $query ) || array_key_exists( 'terms', $query ) || array_key_exists( 'taxonomy', $query ) || array_key_exists( 'include_children', $query ) || array_key_exists( 'field', $query ) || array_key_exists( 'operator', $query );
     835        return is_array( $query ) && ( empty( $query ) || array_key_exists( 'terms', $query ) || array_key_exists( 'taxonomy', $query ) || array_key_exists( 'include_children', $query ) || array_key_exists( 'field', $query ) || array_key_exists( 'operator', $query ) );
    836836    }
    837837
  • trunk/tests/phpunit/tests/term/query.php

    r29931 r30031  
    8484
    8585        $this->assertEquals( array( 'foo', ), $tq->queries[0]['terms'] );
     86    }
     87
     88    /**
     89     * @ticket 30117
     90     */
     91    public function test_construct_empty_strings_array_members_should_be_discarded() {
     92        $q = new WP_Tax_Query( array(
     93            '',
     94            array(
     95                'taxonomy' => 'post_tag',
     96                'terms' => 'foo',
     97            ),
     98        ) );
     99
     100        $this->assertSame( 1, count( $q->queries ) );
    86101    }
    87102
Note: See TracChangeset for help on using the changeset viewer.