From f1771073dc7d7b59468b7dced8bd7633274830d7 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Tue, 20 Jan 2015 19:12:48 +0000 Subject: [PATCH] `WP_Date_Query` date validation should not fail for hour = 0. Props ChriCo, tyxla. Fixes #31067 for trunk. git-svn-id: https://develop.svn.wordpress.org/trunk@31251 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/date.php | 4 ++-- tests/phpunit/tests/date/query.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/date.php b/src/wp-includes/date.php index 58071d3d3a..a35fada6d1 100644 --- a/src/wp-includes/date.php +++ b/src/wp-includes/date.php @@ -368,7 +368,7 @@ class WP_Date_Query { // Hours per day. $min_max_checks['hour'] = array( - 'min' => 1, + 'min' => 0, 'max' => 23 ); @@ -394,7 +394,7 @@ class WP_Date_Query { foreach ( (array) $date_query[ $key ] as $_value ) { $is_between = $_value >= $check['min'] && $_value <= $check['max']; - if ( ! $is_between ) { + if ( ! is_numeric( $_value ) || ! $is_between ) { $error = sprintf( /* translators: Date query invalid date message: 1: invalid value, 2: type of value, 3: minimum valid value, 4: maximum valid value */ __( 'Invalid value %1$s for %2$s. Expected value should be between %3$s and %4$s.' ), diff --git a/tests/phpunit/tests/date/query.php b/tests/phpunit/tests/date/query.php index 2169d88efb..72c7d73f41 100644 --- a/tests/phpunit/tests/date/query.php +++ b/tests/phpunit/tests/date/query.php @@ -857,13 +857,13 @@ class Tests_WP_Date_Query extends WP_UnitTestCase { */ public function test_validate_date_values_hour() { // Valid values. - $hours = range( 1, 23 ); + $hours = range( 0, 23 ); foreach ( $hours as $hour ) { $this->assertTrue( $this->q->validate_date_values( array( 'hour' => $hour ) ) ); } // Invalid values. - $hours = array( -1, 24, 25, 'string who wants to be a int' ); + $hours = array( -1, 24, 25, 'string' ); foreach ( $hours as $hour ) { $this->assertFalse( $this->q->validate_date_values( array( 'hour' => $hour ) ) ); }