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

View File

@@ -96,7 +96,7 @@ class Tests_Canonical extends WP_Canonical_UnitTestCase {
array( '/2010/post-format-test-au/', '/2008/06/02/post-format-test-audio/'), // A Year the post is not in
array( '/post-format-test-au/', '/2008/06/02/post-format-test-audio/'),
array( '/2008/09/03/images-test/3/', array( 'url' => '/2008/09/03/images-test/3/', 'qv' => array( 'name' => 'images-test', 'year' => '2008', 'monthnum' => '09', 'day' => '03', 'page' => '/3' ) ) ), // page = /3 ?!
array( '/2008/09/03/images-test/3/', array( 'url' => '/2008/09/03/images-test/3/', 'qv' => array( 'name' => 'images-test', 'year' => '2008', 'monthnum' => '09', 'day' => '03', 'page' => '3' ) ) ),
array( '/2008/09/03/images-test/?page=3', '/2008/09/03/images-test/3/' ),
array( '/2008/09/03/images-te?page=3', '/2008/09/03/images-test/3/' ),

View File

@@ -0,0 +1,25 @@
<?php
/**
* @group canonical
* @group rewrite
* @group query
*/
class Tests_Canonical_Paged extends WP_Canonical_UnitTestCase {
function test_nextpage() {
$para = 'This is a paragraph.
This is a paragraph.
This is a paragraph.';
$next = '<!--nextpage-->';
$post_id = $this->factory->post->create( array(
'post_status' => 'publish',
'post_content' => "{$para}{$next}{$para}{$next}{$para}"
) );
$link = parse_url( get_permalink( $post_id ), PHP_URL_PATH );
$paged = $link . '4/';
$this->assertCanonical( $paged, $link );
}
}