Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
66 changes: 66 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,70 @@ static function ( $url ) {
$this->wp->parse_request();
$this->assertSame( '', $this->wp->request );
}

/**
* @ticket 65123
*/
public function test_parse_request_ignores_non_scalar_post_type_values_from_get() {
$original_get = $_GET;
$original_post = $_POST;
$original_request = $_SERVER['REQUEST_URI'] ?? null;
$original_self = $_SERVER['PHP_SELF'] ?? null;

$_GET['post_type'] = array( array( 'page' ), 'post' );
$_SERVER['REQUEST_URI'] = '/?post_type[][]=page&post_type[]=post';
$_SERVER['PHP_SELF'] = '/index.php';

$this->wp->parse_request();

$this->assertSame( array( 'post' ), array_values( $this->wp->query_vars['post_type'] ) );

$_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;
}
}

/**
* @ticket 65123
*/
public function test_parse_request_ignores_non_scalar_post_type_values_from_post() {
$original_get = $_GET;
$original_post = $_POST;
$original_request = $_SERVER['REQUEST_URI'] ?? null;
$original_self = $_SERVER['PHP_SELF'] ?? null;

$_POST['post_type'] = array( array( 'page' ), 'post' );
$_SERVER['REQUEST_URI'] = '/';
$_SERVER['PHP_SELF'] = '/index.php';

$this->wp->parse_request();

$this->assertSame( array( 'post' ), array_values( $this->wp->query_vars['post_type'] ) );

$_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;
}
}
}
Loading