Make WordPress Core

Changeset 62047


Ignore:
Timestamp:
03/18/2026 09:02:09 PM (9 days ago)
Author:
SergeyBiryukov
Message:

Query: Check that taxonomy query var is a string in WP_Query::parse_tax_query().

This prevents a fatal error from urldecode() in wp_basename() if an array is passed instead.

Follow-up to [15732], [15824], [15825], [15923], [16155], [50565], [60927].

Props patricedefago, alexodiy, SergeyBiryukov.
Fixes #64870.

Location:
trunk
Files:
2 edited

Legend:

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

    r61878 r62047  
    11901190                );
    11911191
    1192                 if ( ! empty( $t->rewrite['hierarchical'] ) ) {
     1192                if ( is_string( $query_vars[ $t->query_var ] ) && ! empty( $t->rewrite['hierarchical'] ) ) {
    11931193                    $query_vars[ $t->query_var ] = wp_basename( $query_vars[ $t->query_var ] );
    11941194                }
  • trunk/tests/phpunit/tests/query/parseQuery.php

    r59766 r62047  
    234234        $this->assertEmpty( $q->query_vars['attachment_id'] );
    235235    }
     236
     237    /**
     238     * Tests that a fatal error is not thrown when a hierarchical taxonomy query var
     239     * passed to wp_basename() in ::parse_tax_query() is an array instead of a string.
     240     *
     241     * The message that we should not see:
     242     * `TypeError: urldecode(): Argument #1 ($string) must be of type string, array given`.
     243     *
     244     * @ticket 64870
     245     */
     246    public function test_parse_query_hierarchical_taxonomy_query_var_array() {
     247        register_taxonomy(
     248            'wptests_tax',
     249            'post',
     250            array(
     251                'query_var' => 'wptests_tax',
     252                'rewrite'   => array( 'hierarchical' => true ),
     253                'public'    => true,
     254            )
     255        );
     256
     257        $q = new WP_Query(
     258            array(
     259                'wptests_tax' => array( 'term-a', 'term-b' ),
     260            )
     261        );
     262
     263        unregister_taxonomy( 'wptests_tax' );
     264
     265        $this->assertIsArray( $q->posts );
     266    }
    236267}
Note: See TracChangeset for help on using the changeset viewer.