Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/wp-includes/class-wp.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,10 @@ public function parse_request( $extra_query_vars = '' ) {
unset( $this->query_vars['post_type'] );
}
} else {
$this->query_vars['post_type'] = array_intersect( $this->query_vars['post_type'], $queryable_post_types );
$this->query_vars['post_type'] = array_intersect(
array_filter( $this->query_vars['post_type'], 'is_scalar' ),
$queryable_post_types
);
}
}

Expand Down
48 changes: 48 additions & 0 deletions tests/phpunit/tests/wp/parseRequest.php
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s use a single test with a data provider for better coverage, and we can remove the duplicate code.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 6b6be36. I collapsed the GET/POST cases into a single provider-backed test and removed the duplicated setup/cleanup code. I also reran npm run test:php -- --filter Tests_WP_ParseRequest and ./vendor/bin/phpcs --standard=phpcs.xml.dist tests/phpunit/tests/wp/parseRequest.php after the refactor.

Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,52 @@ static function ( $url ) {
$this->wp->parse_request();
$this->assertSame( '', $this->wp->request );
}

/**
* @ticket 65123
* @dataProvider data_parse_request_ignores_non_scalar_post_type_values
*/
public function test_parse_request_ignores_non_scalar_post_type_values( $request_method, $request_uri ) {
$original_get = $_GET;
$original_post = $_POST;
$original_request = $_SERVER['REQUEST_URI'] ?? null;
$original_self = $_SERVER['PHP_SELF'] ?? null;

if ( 'GET' === $request_method ) {
$_GET['post_type'] = array( array( 'page' ), 'post' );
} else {
$_POST['post_type'] = array( array( 'page' ), 'post' );
}

$_SERVER['REQUEST_URI'] = $request_uri;
$_SERVER['PHP_SELF'] = '/index.php';

try {
$this->wp->parse_request();

$this->assertSame( array( 'post' ), array_values( $this->wp->query_vars['post_type'] ) );
} finally {
$_GET = $original_get;
$_POST = $original_post;

if ( null === $original_request ) {
unset( $_SERVER['REQUEST_URI'] );
} else {
$_SERVER['REQUEST_URI'] = $original_request;
}

if ( null === $original_self ) {
unset( $_SERVER['PHP_SELF'] );
} else {
$_SERVER['PHP_SELF'] = $original_self;
}
}
}

public function data_parse_request_ignores_non_scalar_post_type_values() {
return array(
'get' => array( 'GET', '/?post_type[][]=page&post_type[]=post' ),
'post' => array( 'POST', '/' ),
);
}
}
Loading