Query: Discard non-scalar 'm' instead of attempting to sanitize.
`WP_Query` discards most non-array date values ('year', 'monthnum', etc) by casting to integer. Since [25138], the 'm' parameter has been handled as a string; see #24884. However, the string-handling introduced in [25138] blindly attempted to handle arrays and other non-scalar types as strings, resulting in PHP notices and invalid MySQL syntax. Props vortfu. Fixes #36718. git-svn-id: https://develop.svn.wordpress.org/trunk@37324 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
d73d355250
commit
00c39a3f98
@ -1593,7 +1593,7 @@ class WP_Query {
|
||||
$qv['monthnum'] = absint($qv['monthnum']);
|
||||
$qv['day'] = absint($qv['day']);
|
||||
$qv['w'] = absint($qv['w']);
|
||||
$qv['m'] = preg_replace( '|[^0-9]|', '', $qv['m'] );
|
||||
$qv['m'] = is_scalar( $qv['m'] ) ? preg_replace( '|[^0-9]|', '', $qv['m'] ) : '';
|
||||
$qv['paged'] = absint($qv['paged']);
|
||||
$qv['cat'] = preg_replace( '|[^0-9,-]|', '', $qv['cat'] ); // comma separated list of positive or negative integers
|
||||
$qv['author'] = preg_replace( '|[^0-9,-]|', '', $qv['author'] ); // comma separated list of positive or negative integers
|
||||
|
@ -258,6 +258,18 @@ class Tests_Query_Date extends WP_UnitTestCase {
|
||||
$this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36718
|
||||
*/
|
||||
public function test_non_scalar_m_should_be_discarded() {
|
||||
$expected = $this->_get_query_result( );
|
||||
$posts = $this->_get_query_result( array(
|
||||
'm' => array( '1234' ), // ignored
|
||||
) );
|
||||
|
||||
$this->assertEquals( $expected, $posts );
|
||||
}
|
||||
|
||||
public function test_simple_monthnum_expecting_results() {
|
||||
$posts = $this->_get_query_result( array(
|
||||
'monthnum' => 5,
|
||||
|
Loading…
Reference in New Issue
Block a user