Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.1032
diff -u -p -r1.1032 common.inc
--- includes/common.inc	31 Oct 2009 16:06:35 -0000	1.1032
+++ includes/common.inc	1 Nov 2009 04:31:01 -0000
@@ -245,7 +245,7 @@ function drupal_get_profile() {
 function drupal_set_breadcrumb($breadcrumb = NULL) {
   $stored_breadcrumb = &drupal_static(__FUNCTION__);
 
-  if (!is_null($breadcrumb)) {
+  if (isset($breadcrumb)) {
     $stored_breadcrumb = $breadcrumb;
   }
   return $stored_breadcrumb;
@@ -257,7 +257,7 @@ function drupal_set_breadcrumb($breadcru
 function drupal_get_breadcrumb() {
   $breadcrumb = drupal_set_breadcrumb();
 
-  if (is_null($breadcrumb)) {
+  if (!isset($breadcrumb)) {
     $breadcrumb = menu_get_active_breadcrumb();
   }
 
Index: includes/menu.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/menu.inc,v
retrieving revision 1.357
diff -u -p -r1.357 menu.inc
--- includes/menu.inc	17 Oct 2009 11:39:15 -0000	1.357
+++ includes/menu.inc	1 Nov 2009 05:32:38 -0000
@@ -1994,35 +1994,44 @@ function menu_set_active_trail($new_trai
   elseif (!isset($trail)) {
     $trail = array();
     $trail[] = array('title' => t('Home'), 'href' => '<front>', 'localized_options' => array(), 'type' => 0);
+    $menu_names = menu_get_active_menu_names();
     $item = menu_get_item();
+    $non_tab_item = $item;
 
     // Check whether the current item is a local task (displayed as a tab).
-    if ($item['tab_parent']) {
+    if ($item['tab_root']) {
       // The title of a local task is used for the tab, never the page title.
       // Thus, replace it with the item corresponding to the root path to get
       // the relevant href and title. For example, the menu item corresponding
       // to 'admin' is used when on the 'By module' tab at 'admin/by-module'.
       $parts = explode('/', $item['tab_root']);
-      $args = arg();
+      $map = $item['original_map'];
       // Replace wildcards in the root path using the current path.
       foreach ($parts as $index => $part) {
         if ($part == '%') {
-          $parts[$index] = $args[$index];
+          $parts[$index] = $map[$index];
         }
       }
+      // Build a list of candidates, i.e. foo, foo/bar, foo/bar/baz, etc.
+      $candidates = array();
+      $candidate = '';
+      foreach ($parts as $part) {
+        $candidate = ($candidate ? $candidate . '/' : '') . $part;
+        $candidates[] = $candidate;
+      }
+      $root_path = db_query("SELECT link_path FROM {menu_links} ml WHERE ml.menu_name IN (:menus) AND ml.link_path IN (:paths) ORDER BY ml.depth DESC LIMIT 0, 1", array(':menus' => $menu_names, ':paths' => $candidates))->fetchField();
       // Retrieve the menu item using the root path after wildcard replacement.
-      $root_item = menu_get_item(implode('/', $parts));
+      $root_item = menu_get_item($root_path);
       if ($root_item && $root_item['access']) {
-        $item = $root_item;
+        $non_tab_item = $root_item;
       }
     }
-    $menu_names = menu_get_active_menu_names();
     $curr = FALSE;
     // Determine if the current page is a link in any of the active menus.
     if ($menu_names) {
       $query = db_select('menu_links', 'ml');
       $query->fields('ml', array('menu_name'));
-      $query->condition('ml.link_path', $item['href']);
+      $query->condition('ml.link_path', $non_tab_item['href']);
       $query->condition('ml.menu_name', $menu_names, 'IN');
       $result = $query->execute();
       $found = array();
@@ -2039,7 +2048,7 @@ function menu_set_active_trail($new_trai
 
     while ($curr) {
       // Terminate the loop when we find the current path in the active trail.
-      if ($curr['link']['href'] == $item['href']) {
+      if ($curr['link']['href'] == $non_tab_item['href']) {
         $trail[] = $curr['link'];
         $curr = FALSE;
       }
@@ -2052,10 +2061,11 @@ function menu_set_active_trail($new_trai
         list($key, $curr) = each($tree);
       }
     }
+
     // Make sure the current page is in the trail (needed for the page title),
     // but exclude tabs and the front page.
     $last = count($trail) - 1;
-    if ($trail[$last]['href'] != $item['href'] && !(bool)($item['type'] & MENU_IS_LOCAL_TASK) && !drupal_is_front_page()) {
+    if ($trail[$last]['href'] != $item['href'] && !drupal_is_front_page()) {
       $trail[] = $item;
     }
   }
