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 ) { |
294 | 294 | |
295 | 295 | // paging and feeds |
296 | 296 | 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'] ) ) { |
298 | 305 | // Strip off paging and feed |
299 | 306 | $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 |
301 | 308 | $redirect['path'] = preg_replace( "#/{$wp_rewrite->comments_pagination_base}-[0-9]+?(/+)?$#", '/', $redirect['path'] ); // strip off any existing comment paging |
302 | 309 | } |
303 | 310 | |
diff --git a/tests/phpunit/tests/canonical.php b/tests/phpunit/tests/canonical.php
index a2bbc06..1e205c6 100644
a
|
b
|
class Tests_Canonical extends WP_Canonical_UnitTestCase { |
213 | 213 | // Todo: Endpoints (feeds, trackbacks, etc), More fuzzed mixed query variables, comment paging, Home page (Static) |
214 | 214 | ); |
215 | 215 | } |
| 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 | } |
216 | 228 | } |