Skip to content

Commit c4a6004

Browse files
committed
Permalinks: Ignore malformed post type query arrays
1 parent 8270db8 commit c4a6004

2 files changed

Lines changed: 70 additions & 1 deletion

File tree

src/wp-includes/class-wp.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,10 @@ public function parse_request( $extra_query_vars = '' ) {
382382
unset( $this->query_vars['post_type'] );
383383
}
384384
} else {
385-
$this->query_vars['post_type'] = array_intersect( $this->query_vars['post_type'], $queryable_post_types );
385+
$this->query_vars['post_type'] = array_intersect(
386+
array_filter( $this->query_vars['post_type'], 'is_scalar' ),
387+
$queryable_post_types
388+
);
386389
}
387390
}
388391

tests/phpunit/tests/wp/parseRequest.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,70 @@ static function ( $url ) {
5656
$this->wp->parse_request();
5757
$this->assertSame( '', $this->wp->request );
5858
}
59+
60+
/**
61+
* @ticket 65123
62+
*/
63+
public function test_parse_request_ignores_non_scalar_post_type_values_from_get() {
64+
$original_get = $_GET;
65+
$original_post = $_POST;
66+
$original_request = $_SERVER['REQUEST_URI'] ?? null;
67+
$original_self = $_SERVER['PHP_SELF'] ?? null;
68+
69+
$_GET['post_type'] = array( array( 'page' ), 'post' );
70+
$_SERVER['REQUEST_URI'] = '/?post_type[][]=page&post_type[]=post';
71+
$_SERVER['PHP_SELF'] = '/index.php';
72+
73+
$this->wp->parse_request();
74+
75+
$this->assertSame( array( 'post' ), array_values( $this->wp->query_vars['post_type'] ) );
76+
77+
$_GET = $original_get;
78+
$_POST = $original_post;
79+
80+
if ( null === $original_request ) {
81+
unset( $_SERVER['REQUEST_URI'] );
82+
} else {
83+
$_SERVER['REQUEST_URI'] = $original_request;
84+
}
85+
86+
if ( null === $original_self ) {
87+
unset( $_SERVER['PHP_SELF'] );
88+
} else {
89+
$_SERVER['PHP_SELF'] = $original_self;
90+
}
91+
}
92+
93+
/**
94+
* @ticket 65123
95+
*/
96+
public function test_parse_request_ignores_non_scalar_post_type_values_from_post() {
97+
$original_get = $_GET;
98+
$original_post = $_POST;
99+
$original_request = $_SERVER['REQUEST_URI'] ?? null;
100+
$original_self = $_SERVER['PHP_SELF'] ?? null;
101+
102+
$_POST['post_type'] = array( array( 'page' ), 'post' );
103+
$_SERVER['REQUEST_URI'] = '/';
104+
$_SERVER['PHP_SELF'] = '/index.php';
105+
106+
$this->wp->parse_request();
107+
108+
$this->assertSame( array( 'post' ), array_values( $this->wp->query_vars['post_type'] ) );
109+
110+
$_GET = $original_get;
111+
$_POST = $original_post;
112+
113+
if ( null === $original_request ) {
114+
unset( $_SERVER['REQUEST_URI'] );
115+
} else {
116+
$_SERVER['REQUEST_URI'] = $original_request;
117+
}
118+
119+
if ( null === $original_self ) {
120+
unset( $_SERVER['PHP_SELF'] );
121+
} else {
122+
$_SERVER['PHP_SELF'] = $original_self;
123+
}
124+
}
59125
}

0 commit comments

Comments
 (0)