diff --git a/core/modules/node/node.module b/core/modules/node/node.module index c7be759..db5cae6 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -2058,7 +2058,8 @@ function node_menu() { ); $items['rss.xml'] = array( 'title' => 'RSS feed', - 'page callback' => 'node_feed', + 'page callback' => 'node_view_feed', + 'page arguments' => array(1), 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); @@ -2552,6 +2553,14 @@ function node_block_list_alter(&$blocks) { } /** + * Page callback wrapper for node_feed(). + */ +function node_view_feed($nids) { + // Users may try to view a non-existent feed page, so we give them a 404 error. + return ($nids === '') ? node_feed(FALSE, array()) : MENU_NOT_FOUND; +} + +/** * Page callback: Generates and prints an RSS feed. * * Path: rss.xml @@ -2587,40 +2596,43 @@ function node_feed($nids = FALSE, $channel = array()) { ->fetchCol(); } - $item_length = variable_get('feed_item_length', 'fulltext'); + $items = ''; $namespaces = array('xmlns:dc' => 'http://purl.org/dc/elements/1.1/'); - $teaser = ($item_length == 'teaser'); + if(!empty($nids)) { + $item_length = variable_get('feed_item_length', 'fulltext'); + $teaser = ($item_length == 'teaser'); - // Load all nodes to be rendered. - $nodes = node_load_multiple($nids); - $items = ''; - foreach ($nodes as $node) { - $item_text = ''; - - $node->link = url("node/$node->nid", array('absolute' => TRUE)); - $node->rss_namespaces = array(); - $node->rss_elements = array( - array('key' => 'pubDate', 'value' => gmdate('r', $node->created)), - array('key' => 'dc:creator', 'value' => $node->name), - array('key' => 'guid', 'value' => $node->nid . ' at ' . $base_url, 'attributes' => array('isPermaLink' => 'false')) - ); + // Load all nodes to be rendered. + $nodes = node_load_multiple($nids); - // The node gets built and modules add to or modify $node->rss_elements - // and $node->rss_namespaces. - $build = node_view($node, 'rss'); - unset($build['#theme']); + foreach ($nodes as $node) { + $item_text = ''; - if (!empty($node->rss_namespaces)) { - $namespaces = array_merge($namespaces, $node->rss_namespaces); - } + $node->link = url("node/$node->nid", array('absolute' => TRUE)); + $node->rss_namespaces = array(); + $node->rss_elements = array( + array('key' => 'pubDate', 'value' => gmdate('r', $node->created)), + array('key' => 'dc:creator', 'value' => $node->name), + array('key' => 'guid', 'value' => $node->nid . ' at ' . $base_url, 'attributes' => array('isPermaLink' => 'false')) + ); - if ($item_length != 'title') { - // We render node contents and force links to be last. - $build['links']['#weight'] = 1000; - $item_text .= drupal_render($build); - } + // The node gets built and modules add to or modify $node->rss_elements + // and $node->rss_namespaces. + $build = node_view($node, 'rss'); + unset($build['#theme']); - $items .= format_rss_item($node->title, $node->link, $item_text, $node->rss_elements); + if (!empty($node->rss_namespaces)) { + $namespaces = array_merge($namespaces, $node->rss_namespaces); + } + + if ($item_length != 'title') { + // We render node contents and force links to be last. + $build['links']['#weight'] = 1000; + $item_text .= drupal_render($build); + } + + $items .= format_rss_item($node->title, $node->link, $item_text, $node->rss_elements); + } } $channel_defaults = array( diff --git a/core/modules/node/node.test b/core/modules/node/node.test index f828164..4b4624f 100644 --- a/core/modules/node/node.test +++ b/core/modules/node/node.test @@ -813,6 +813,9 @@ class NodeRSSContentTestCase extends DrupalWebTestCase { $this->drupalGet("node/$node->nid"); $this->assertNoText($rss_only_content, t('Node content designed for RSS doesn\'t appear when viewing node.')); + // Check that the node feed page does not try to interpret additional path + // components as arguments for node_feed(). + $this->drupalGet('rss.xml/' . $this->randomName() . '/' . $this->randomName()); } }