diff --git src/wp-includes/functions.php src/wp-includes/functions.php
index 914cbb9..8b99405 100644
|
|
|
function bool_from_yn( $yn ) { |
| 1213 | 1213 | function do_feed() { |
| 1214 | 1214 | global $wp_query; |
| 1215 | 1215 | |
| 1216 | | // Determine if we are looking at the main comment feed |
| 1217 | | $is_main_comments_feed = ( $wp_query->is_comment_feed() && ! $wp_query->is_singular() ); |
| 1218 | | |
| 1219 | | /* |
| 1220 | | * Check the queried object for the existence of posts if it is not a feed for an archive, |
| 1221 | | * search result, or main comments. By checking for the absense of posts we can prevent rendering the feed |
| 1222 | | * templates at invalid endpoints. e.g.) /wp-content/plugins/feed/ |
| 1223 | | */ |
| 1224 | | if ( ! $wp_query->have_posts() && ! ( $wp_query->is_archive() || $wp_query->is_search() || $is_main_comments_feed ) ) { |
| 1225 | | wp_die( __( 'ERROR: This is not a valid feed.' ), '', array( 'response' => 404 ) ); |
| 1226 | | } |
| 1227 | | |
| 1228 | 1216 | $feed = get_query_var( 'feed' ); |
| 1229 | 1217 | |
| 1230 | 1218 | // Remove the pad, if present. |
diff --git tests/phpunit/tests/feed/rss2.php tests/phpunit/tests/feed/rss2.php
index fab3726..d48bc88 100644
|
|
|
class Tests_Feeds_RSS2 extends WP_UnitTestCase { |
| 457 | 457 | // There should only be one <rss> child element. |
| 458 | 458 | $this->assertEquals( 1, count( $rss ) ); |
| 459 | 459 | } |
| 460 | | |
| 461 | | /* |
| 462 | | * Check to make sure we are not rendering feed templates for invalid feed endpoints. |
| 463 | | * e.g. https://example.com/wp-content/feed/ |
| 464 | | * |
| 465 | | * @ticket 30210 |
| 466 | | */ |
| 467 | | function test_invalid_feed_endpoint() { |
| 468 | | // An example of an invalid feed endpoint |
| 469 | | $this->go_to( 'wp-content/feed/' ); |
| 470 | | |
| 471 | | // Queries performed on invalid feed endpoints should never contain posts. |
| 472 | | $this->assertFalse( have_posts() ); |
| 473 | | |
| 474 | | // This is the assertion. Once the exception is thrown in do_feed, execution stops, preventing futher assertions. |
| 475 | | $this->setExpectedException( 'WPDieException', 'ERROR: This is not a valid feed.' ); |
| 476 | | do_feed(); |
| 477 | | } |
| 478 | | |
| 479 | | /* |
| 480 | | * Make sure the requested feed is registered before rendering the requested template. |
| 481 | | * |
| 482 | | * @ticket 30210 |
| 483 | | */ |
| 484 | | function test_nonexistent_feeds() { |
| 485 | | global $wp_rewrite; |
| 486 | | $badfeed = 'badfeed'; |
| 487 | | |
| 488 | | $this->assertNotContains( $badfeed, $wp_rewrite->feeds ); |
| 489 | | |
| 490 | | $this->go_to( '/?feed=' . $badfeed ); |
| 491 | | |
| 492 | | // This is the assertion. Once the exception is thrown in do_feed, execution stops, preventing futher assertions. |
| 493 | | $this->setExpectedException( 'WPDieException', 'ERROR: This is not a valid feed template.' ); |
| 494 | | do_feed(); |
| 495 | | } |
| 496 | | |
| 497 | 460 | } |