Make WordPress Core

Ticket #14773: 12456.5.diff

File 12456.5.diff, 2.3 KB (added by boonebgorges, 10 years ago)

Contains .4.patch plus the extracted existing test. See #30284.

  • src/wp-includes/canonical.php

    diff --git src/wp-includes/canonical.php src/wp-includes/canonical.php
    index bd10ce5..36d3a35 100644
    function redirect_canonical( $requested_url = null, $do_redirect = true ) { 
    245245                }
    246246
    247247                // Post Paging
    248                 if ( is_singular() && ! is_front_page() && get_query_var('page') ) {
    249                         if ( !$redirect_url )
    250                                 $redirect_url = get_permalink( get_queried_object_id() );
    251                         $redirect_url = trailingslashit( $redirect_url ) . user_trailingslashit( get_query_var( 'page' ), 'single_paged' );
    252                         $redirect['query'] = remove_query_arg( 'page', $redirect['query'] );
     248                if ( is_singular() && ! is_front_page() ) {
     249                        if ( get_query_var('page') ) {
     250                                if ( ! $redirect_url )
     251                                        $redirect_url = set_url_scheme( get_permalink( get_queried_object_id() ) );
     252                                $redirect_url = trailingslashit( $redirect_url ) . user_trailingslashit( get_query_var( 'page' ), 'single_paged' );
     253                                $redirect['query'] = remove_query_arg( 'page', $redirect['query'] );
     254                        } else {
     255                                $post_url = set_url_scheme( get_permalink( get_queried_object_id() ) );
     256                                // If the full post's URL is not within the requested url, lets redirect there.
     257                                if ( strpos( $requested_url, $post_url ) === false )
     258                                        $redirect_url = $post_url;
     259                        }
    253260                }
    254261
    255262                // paging and feeds
  • tests/phpunit/tests/canonical.php

    diff --git tests/phpunit/tests/canonical.php tests/phpunit/tests/canonical.php
    index 458db03..dc7400e 100644
    class Tests_Canonical extends WP_Canonical_UnitTestCase { 
    7676//                      array( '/2008/?category_name=cat-a', array( 'url' => '/2008/?category_name=cat-a', 'qv' => array('category_name' => 'cat-a', 'year' => '2008' ) ) ),
    7777
    7878                        // Pages
     79                        array( '/sample------page/', array( 'url' => '/sample-page/', 'qv' => array('pagename' => 'sample-page', 'page' => '' ) ), 14773 ),
     80                        array( '/sample-page---/', array( 'url' => '/sample-page/', 'qv' => array('pagename' => 'sample-page', 'page' => '' ) ), 14773 ),
     81                        array( '/---sample-page/', array( 'url' => '/sample-page/', 'qv' => array('pagename' => 'sample-page', 'page' => '' ) ), 14773 ),
    7982                        array( '/child-page-1/', '/parent-page/child-page-1/'),
    8083                        array( '/?page_id=144', '/parent-page/child-page-1/'),
    8184                        array( '/abo', '/about/' ),