Make WordPress Core

Changeset 48166


Ignore:
Timestamp:
06/25/2020 11:39:23 AM (6 years ago)
Author:
SergeyBiryukov
Message:

Canonical: Move trailing slash handling for robots.txt and sitemaps to a single condition.

Give the unit test a more descriptive name.

Follow-up to [48153], [48155].

See #48025.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/canonical.php

    r48153 r48166  
    5858        }
    5959
    60         if ( is_admin() || is_search() || is_preview() || is_trackback()
    61                 || is_favicon() || ( $is_IIS && ! iis7_supports_permalinks() )
     60        if ( is_admin() || is_search() || is_preview() || is_trackback() || is_favicon()
     61                || ( $is_IIS && ! iis7_supports_permalinks() )
    6262        ) {
    6363                return;
    … …  
    656656        }
    657657
    658         // Remove trailing slash for sitemaps requests.
    659         if ( ! empty( get_query_var( 'sitemap' ) ) || ! empty( get_query_var( 'sitemap-stylesheet' ) ) ) {
     658        // Remove trailing slash for robots.txt or sitemap requests.
     659        if ( is_robots()
     660                || ! empty( get_query_var( 'sitemap' ) ) || ! empty( get_query_var( 'sitemap-stylesheet' ) )
     661        ) {
    660662                $redirect['path'] = untrailingslashit( $redirect['path'] );
    661663        }
    … …  
    681683        ) {
    682684                $redirect['host'] = $original['host'];
    683         }
    684 
    685         // Even if the permalink structure ends with a slash, remove slash robots.txt.
    686         if ( is_robots() ) {
    687                 $redirect['path'] = untrailingslashit( $redirect['path'] );
    688685        }
    689686
  • trunk/tests/phpunit/tests/canonical/robots.php

    r48155 r48166  
    88class Tests_Canonical_Robots extends WP_Canonical_UnitTestCase {
    99
    10         function setUp() {
    11                 parent::setUp();
    12         }
    13 
    14         function test_robots_url() {
    15                 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
     10        public function test_remove_trailing_slashes_for_robots_requests() {
     11                $this->set_permalink_structure( '/%postname%/' );
    1612                $this->assertCanonical( '/robots.txt', '/robots.txt' );
    1713                $this->assertCanonical( '/robots.txt/', '/robots.txt' );
  • trunk/tests/phpunit/tests/canonical/sitemaps.php

    r48072 r48166  
    88 */
    99class Tests_Canonical_Sitemaps extends WP_Canonical_UnitTestCase {
     10
    1011        public function setUp() {
    1112                parent::setUp();
    … …  
    3940                $this->assertCanonical( '/wp-sitemap.xsl/', '/wp-sitemap.xsl' );
    4041        }
     42
    4143}
Note: See TracChangeset for help on using the changeset viewer.