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.


git-svn-id: https://develop.svn.wordpress.org/trunk@34492 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2015-09-24 14:03:05 +00:00
parent c9093207df
commit 0111ecef55
6 changed files with 54 additions and 8 deletions
+4 -2
View File
@@ -1071,8 +1071,10 @@ class WP_Rewrite {
$sub1 .= '?$';
$sub2 .= '?$';
//post pagination, e.g. <permalink>/2/
$match = $match . '(/[0-9]+)?/?$';
// Post pagination, e.g. <permalink>/2/
// Previously: '(/[0-9]+)?/?$', which produced '/2' for page.
// When cast to int, returned 0.
$match = $match . '(?:/([0-9]+))?/?$';
$query = $index . '?' . $query . '&page=' . $this->preg_index($num_toks + 1);
} else { //not matching a permalink so this is a lot simpler
//close the match and finalise the query