Ticket #31083: 31083.patch
File 31083.patch, 3.4 KB (added by , 10 years ago) |
---|
-
tests/phpunit/tests/date/query.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
645 645 'day' => 8, 646 646 'year' => 2014, 647 647 ), 648 '21 June 1987', 648 649 ); 649 650 650 651 foreach ( $valid_args as $args ) { … … 669 670 array( 670 671 'week' => 54, 671 672 ), 673 'I am a valid date string!', 674 false, 675 true, 676 3.14159265359 677 672 678 ); 673 679 674 680 foreach ( $invalid_args as $args ) { -
src/wp-includes/date.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
291 291 * validation routine continue to be sure that all invalid 292 292 * values generate errors too. 293 293 */ 294 if ( array_key_exists( 'before', $date_query ) && is_array( $date_query['before'] ) ){295 $valid = $this->validate_ date_values( $date_query['before']);294 if ( array_key_exists( 'before', $date_query ) ) { 295 $valid = $this->validate_before_after_args( $date_query[ 'before' ], 'before' ); 296 296 } 297 297 298 if ( array_key_exists( 'after', $date_query ) && is_array( $date_query['after'] ) ){299 $valid = $this->validate_ date_values( $date_query['after']);298 if ( array_key_exists( 'after', $date_query ) ) { 299 $valid = $this->validate_before_after_args( $date_query[ 'after' ], 'after' ); 300 300 } 301 301 302 302 // Array containing all min-max checks. … … 394 394 foreach ( (array) $date_query[ $key ] as $_value ) { 395 395 $is_between = $_value >= $check['min'] && $_value <= $check['max']; 396 396 397 if ( ! is_numeric( $_value ) || !$is_between ) {397 if ( ! $is_between ) { 398 398 $error = sprintf( 399 399 /* translators: Date query invalid date message: 1: invalid value, 2: type of value, 3: minimum valid value, 4: maximum valid value */ 400 400 __( 'Invalid value %1$s for %2$s. Expected value should be between %3$s and %4$s.' ), 401 401 '<code>' . esc_html( $_value ) . '</code>', 402 402 '<code>' . esc_html( $key ) . '</code>', … … 458 458 } 459 459 460 460 return $valid; 461 } 462 463 /** 464 * Validates the before/after date-query args. 465 * 466 * @since 4.1.1 467 * 468 * @param string|array $args the date-query args for before/after 469 * @param string $type the type "before" or "after" 470 * 471 * @return bool true|false 472 */ 473 public function validate_before_after_args( $args, $type ) { 474 475 if ( is_array( $args ) ) { 476 return $this->validate_date_values( $args ); 477 } 478 479 if ( is_string( $args ) ) { 480 $valid = ! ! strtotime( $args ); 481 482 if ( ! $valid ) { 483 $error = sprintf( 484 _x( 'Invalid time string %1$s for %2$s.', '1: time-string, 2: "before" or "after"' ), 485 '<code>' . $args . '</code>', 486 $type 487 ); 488 _doing_it_wrong( __CLASS__, $error, '4.1.1' ); 489 } 490 491 return $valid; 492 } 493 494 $error = sprintf( 495 _x( 'Invalid type %1$s for %2$s. Excepted string or array', '1: argument type, 2: "before" or "after"' ), 496 '<code>' . gettype( $args ) . '</code>', 497 '<strong>' . $type . '</strong>' 498 ); 499 500 _doing_it_wrong( __CLASS__, $error, '4.1.1' ); 501 502 return false; 461 503 } 462 504