WordPress.org

Make WordPress Core

Ticket #43539: 43539.diff

File 43539.diff, 2.4 KB (added by soulseekah, 4 years ago)

Tests + patch

  • src/wp-includes/canonical.php

    diff --git a/src/wp-includes/canonical.php b/src/wp-includes/canonical.php
    index ad219c2..b2bba4b 100644
    a b function redirect_canonical( $requested_url = null, $do_redirect = true ) { 
    294294
    295295                        // paging and feeds
    296296                if ( get_query_var( 'paged' ) || is_feed() || get_query_var( 'cpage' ) ) {
    297                         while ( preg_match( "#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", $redirect['path'] ) || preg_match( '#/(comments/?)?(feed|rss|rdf|atom|rss2)(/+)?$#', $redirect['path'] ) || preg_match( "#/{$wp_rewrite->comments_pagination_base}-[0-9]+(/+)?$#", $redirect['path'] ) ) {
     297
     298                        $feeds = array();
     299                        foreach ( $wp_rewrite->feeds as $_feed ) {
     300                                $feeds[] = preg_quote( $_feed, '#' );
     301                        }
     302                        $feeds = implode( '|', $feeds );
     303
     304                        while ( preg_match( "#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", $redirect['path'] ) || preg_match( "#/(comments/?)?($feeds)(/+)?$#", $redirect['path'] ) || preg_match( "#/{$wp_rewrite->comments_pagination_base}-[0-9]+(/+)?$#", $redirect['path'] ) ) {
    298305                                // Strip off paging and feed
    299306                                $redirect['path'] = preg_replace( "#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", '/', $redirect['path'] ); // strip off any existing paging
    300                                 $redirect['path'] = preg_replace( '#/(comments/?)?(feed|rss2?|rdf|atom)(/+|$)#', '/', $redirect['path'] ); // strip off feed endings
     307                                $redirect['path'] = preg_replace( "#/(comments/?)?($feeds)(/+|$)#", '/', $redirect['path'] ); // strip off feed endings
    301308                                $redirect['path'] = preg_replace( "#/{$wp_rewrite->comments_pagination_base}-[0-9]+?(/+)?$#", '/', $redirect['path'] ); // strip off any existing comment paging
    302309                        }
    303310
  • tests/phpunit/tests/canonical.php

    diff --git a/tests/phpunit/tests/canonical.php b/tests/phpunit/tests/canonical.php
    index a2bbc06..1e205c6 100644
    a b class Tests_Canonical extends WP_Canonical_UnitTestCase { 
    213213                        // Todo: Endpoints (feeds, trackbacks, etc), More fuzzed mixed query variables, comment paging, Home page (Static)
    214214                );
    215215        }
     216
     217        /**
     218         * @ticket 43539
     219         */
     220        public function test_canonical_custom_feed() {
     221                add_feed( 'test', '__return_false' );
     222                flush_rewrite_rules();
     223
     224                $this->assertCanonical( '/?feed=test', '/feed/test/', 43539 );
     225                $this->assertCanonical( '/feed/test/', '/feed/test/', 43539 );
     226                $this->assertCanonical( '/feed/test', '/feed/test/', 43539 );
     227        }
    216228}