Make WordPress Core

Ticket #43539: 43539.1.diff

File 43539.1.diff, 3.4 KB (added by soulseekah, 5 years ago)

Fix global scope infection

  • 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
  • src/wp-includes/class-wp-rewrite.php

    diff --git a/src/wp-includes/class-wp-rewrite.php b/src/wp-includes/class-wp-rewrite.php
    index 337a811..82b9879 100644
    a b class WP_Rewrite { 
    858858         */
    859859        public function generate_rewrite_rules( $permalink_structure, $ep_mask = EP_NONE, $paged = true, $feed = true, $forcomments = false, $walk_dirs = true, $endpoints = true ) {
    860860                // Build a regex to match the feed section of URLs, something like (feed|atom|rss|rss2)/?
    861                 $feedregex2 = '';
    862                 foreach ( (array) $this->feeds as $feed_name ) {
    863                         $feedregex2 .= $feed_name . '|';
     861                $feedregex2 = array();
     862                foreach ( $this->feeds as $feed ) {
     863                        $feedregex2[] = preg_quote( $feed, '#' );
    864864                }
    865                 $feedregex2 = '(' . trim( $feedregex2, '|' ) . ')/?$';
     865                $feedregex2 = '(' . implode( '|', $feedregex2 ) . ')/?$';
    866866
    867867                /*
    868868                 * $feedregex is identical but with /feed/ added on as well, so URLs like <permalink>/feed/atom
  • tests/phpunit/tests/canonical.php

    diff --git a/tests/phpunit/tests/canonical.php b/tests/phpunit/tests/canonical.php
    index a2bbc06..95254b0 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
     228                // Cleanup
     229                global $wp_rewrite;
     230                array_pop( $wp_rewrite->feeds );
     231        }
    216232}