Make WordPress Core

Ticket #10935: 10935.5.diff

File 10935.5.diff, 3.5 KB (added by wonderboymusic, 12 years ago)
  • tests/phpunit/tests/query/conditionals.php

     
    629629        // '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1',
    630630        // '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
    631631        // '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]',
     632
     633        function test_bad_dates() {
     634                $this->go_to( '/2013/13/13/' );
     635                $this->assertQueryTrue( 'is_404' );
     636
     637                $this->go_to( '/2013/11/41/' );
     638                $this->assertQueryTrue( 'is_404' );
     639        }
    632640}
  • tests/phpunit/tests/canonical.php

     
    239239
    240240                        array( '/?year=2008', '/2008/'),
    241241
     242                        array( '/2012/13/', '/2012/'),
     243                        array( '/2012/11/51/', '/2012/11/'),
     244
    242245                        // Authors
    243246                        array( '/?author=%d', '/author/canonical-author/' ),
    244247//                      array( '/?author=%d&year=2008', '/2008/?author=3'),
  • src/wp-includes/query.php

     
    15131513
    15141514                        if ( $qv['day'] ) {
    15151515                                if ( ! $this->is_date ) {
    1516                                         $this->is_day = true;
    1517                                         $this->is_date = true;
     1516                                        $date = sprintf( '%04d-%02d-%02d', $qv['year'], $qv['monthnum'], $qv['day'] );
     1517                                        if ( $qv['monthnum'] && $qv['year'] && ! wp_checkdate( $qv['monthnum'], $qv['day'], $qv['year'], $date ) ) {
     1518                                                $qv['error'] = '404';
     1519                                        } else {
     1520                                                $this->is_day = true;
     1521                                                $this->is_date = true;
     1522                                        }
    15181523                                }
    15191524                        }
    15201525
    15211526                        if ( $qv['monthnum'] ) {
    15221527                                if ( ! $this->is_date ) {
    1523                                         $this->is_month = true;
    1524                                         $this->is_date = true;
     1528                                        if ( 12 < $qv['monthnum'] ) {
     1529                                                $qv['error'] = '404';
     1530                                        } else {
     1531                                                $this->is_month = true;
     1532                                                $this->is_date = true;
     1533                                        }
    15251534                                }
    15261535                        }
    15271536
  • src/wp-includes/canonical.php

     
    101101                        }
    102102                }
    103103
     104                if ( get_query_var( 'day' ) && get_query_var( 'monthnum' ) && get_query_var( 'year' ) ) {
     105                        $year  = get_query_var( 'year' );
     106                        $month = get_query_var( 'monthnum' );
     107                        $day   = get_query_var( 'day' );
     108                        $date  = sprintf( '%04d-%02d-%02d', $year, $month, $day );
     109                        if ( ! wp_checkdate( $month, $day, $year, $date ) ) {
     110                                $redirect_url = get_month_link( $year, $month );
     111                                $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'year', 'monthnum', 'day' ), $redirect_url );
     112                        }
     113                } elseif ( get_query_var( 'monthnum' ) && get_query_var( 'year' ) && 12 < get_query_var( 'monthnum' ) ) {
     114                        $redirect_url = get_year_link( get_query_var( 'year' ) );
     115                        $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'year', 'monthnum' ), $redirect_url );
     116                }
     117
    104118                if ( ! $redirect_url ) {
    105119                        if ( $redirect_url = redirect_guess_404_permalink() ) {
    106120                                $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 );