Skip to content

Commit dab1852

Browse files
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. git-svn-id: https://develop.svn.wordpress.org/trunk@62047 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 58ecd43 commit dab1852

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/wp-includes/class-wp-query.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ public function parse_tax_query( &$query_vars ) {
11891189
'field' => 'slug',
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
}
11951195

tests/phpunit/tests/query/parseQuery.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,35 @@ public function test_parse_query_attachment_id_nonscalar() {
233233

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
}

0 commit comments

Comments
 (0)