Make WordPress Core


Ignore:
Timestamp:
09/24/2015 02:03:05 PM (9 years ago)
Author:
wonderboymusic
Message:

Canonical/Rewrite: sanity check posts that are paged with <!--nextpage-->. Page numbers past the max number of pages are returning the last page of content and causing infinite duplicate content.

Awesome rewrite bug: the page query var was being set to '/4' in $wp. When cast to int, it returns 0 (Bless you, PHP). WP_Query calls trim( $page, '/' ) when setting its own query var. The few places that were checking page before posts were queried now have sanity checks, so that these changes work without flushing rewrites.

Adds/updates unit tests.

Props wonderboymusic, dd32.
See #11694.

File:
1 edited

Legend:

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

    r33751 r34492  
    10721072                    $sub2 .= '?$';
    10731073
    1074                     //post pagination, e.g. <permalink>/2/
    1075                     $match = $match . '(/[0-9]+)?/?$';
     1074                    // Post pagination, e.g. <permalink>/2/
     1075                    // Previously: '(/[0-9]+)?/?$', which produced '/2' for page.
     1076                    // When cast to int, returned 0.
     1077                    $match = $match . '(?:/([0-9]+))?/?$';
    10761078                    $query = $index . '?' . $query . '&page=' . $this->preg_index($num_toks + 1);
    10771079                } else { //not matching a permalink so this is a lot simpler
Note: See TracChangeset for help on using the changeset viewer.