Make WordPress Core

Ticket #10935: canonical-bad-dates.diff

File canonical-bad-dates.diff, 2.9 KB (added by wonderboymusic, 14 years ago)
  • wp-includes/functions.php

     
    34973497}
    34983498
    34993499/**
     3500 * Validates day as 1-31 or specific to month when passed
     3501 *
     3502 * @since 3.5.0
     3503 * @param int $day
     3504 * @param int $month
     3505 * @return bool
     3506 */
     3507function wp_is_valid_day( $day, $month, $year ) {
     3508        return checkdate( $month, $day, $year );
     3509}
     3510
     3511/**
     3512 * Validates month as 1-12
     3513 *
     3514 * @since 3.5.0
     3515 * @param int $month
     3516 * @return bool
     3517 */
     3518function wp_is_valid_month( $month ) {
     3519        $month = (int) $month;
     3520       
     3521        return ! ( empty( $month ) || 12 < $month );
     3522}
     3523
     3524/**
    35003525 * Finds hierarchy loops using a callback function that maps object IDs to parent IDs.
    35013526 *
    35023527 * @since 3.1.0
  • wp-includes/query.php

     
    15011501
    15021502                        if ( $qv['day'] ) {
    15031503                                if ( ! $this->is_date ) {
    1504                                         $this->is_day = true;
    1505                                         $this->is_date = true;
     1504                                        if ( $qv['monthnum'] &&  $qv['year'] && ! wp_is_valid_day( $qv['day'], $qv['monthnum'], $qv['year'] ) ) {
     1505                                                $qv['error'] = '404';
     1506                                        } else {
     1507                                                $this->is_day = true;
     1508                                                $this->is_date = true;                                         
     1509                                        }
    15061510                                }
    15071511                        }
    15081512
    1509                         if ( $qv['monthnum'] ) {
     1513                        if ( $qv['monthnum'] ) {                               
    15101514                                if ( ! $this->is_date ) {
    1511                                         $this->is_month = true;
    1512                                         $this->is_date = true;
     1515                                        if ( wp_is_valid_month( $qv['monthnum'] ) ) {
     1516                                                $this->is_month = true;
     1517                                                $this->is_date = true;
     1518                                        } else {
     1519                                                $qv['error'] = '404';
     1520                                        }
    15131521                                }
    15141522                        }
    15151523
  • wp-includes/canonical.php

     
    101101                        }
    102102                }
    103103
     104                if ( get_query_var( 'day' ) && get_query_var( 'monthnum' ) && get_query_var( 'year' ) && ! wp_is_valid_day( get_query_var( 'day' ), get_query_var( 'monthnum' ), get_query_var( 'year' ) ) ) {
     105                        $redirect_url = get_month_link( get_query_var( 'year' ), get_query_var( 'monthnum' ) );
     106                        $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'year', 'monthnum', 'day' ), $redirect_url );
     107                } elseif ( get_query_var( 'monthnum' ) && get_query_var( 'year' ) && ! wp_is_valid_month( get_query_var( 'monthnum' ) ) ) {
     108                        $redirect_url = get_year_link( get_query_var( 'year' ) );
     109                        $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'year', 'monthnum' ), $redirect_url );
     110                }               
     111
    104112                if ( ! $redirect_url ) {
    105113                        if ( $redirect_url = redirect_guess_404_permalink() ) {
    106114                                $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'page', 'feed', 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url );