=== modified file 'includes/menu.inc'
--- includes/menu.inc	2008-07-10 10:58:01 +0000
+++ includes/menu.inc	2008-07-31 04:32:44 +0000
@@ -603,8 +603,8 @@ function _menu_item_localize(&$item, $ma
  */
 function _menu_translate(&$router_item, $map, $to_arg = FALSE) {
   $path_map = $map;
-  if (!_menu_load_objects($router_item, $map)) {
-    // An error occurred loading an object.
+  if (!preg_match($router_item['mask'], implode($map, '/')) || !_menu_load_objects($router_item, $map)) {
+    // Either the path did not validate or an error occurred loading an object.
     $router_item['access'] = FALSE;
     return FALSE;
   }
@@ -686,6 +686,10 @@ function _menu_link_translate(&$item) {
     $item['localized_options'] = $item['options'];
   }
   else {
+    if (!preg_match($item['mask'], $item['link_path'])) {
+      $item['access'] = FALSE;
+      return FALSE;
+    }
     $map = explode('/', $item['link_path']);
     _menu_link_map_translate($map, $item['to_arg_functions']);
     $item['href'] = implode('/', $map);
@@ -870,7 +874,7 @@ function menu_tree_all_data($menu_name =
       // LEFT JOIN since there is no match in {menu_router} for an external
       // link.
       $data['tree'] = menu_tree_data(db_query("
-        SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.*
+        SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, m.description, m.mask, ml.*
         FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path
         WHERE ml.menu_name = '%s'" . $where . "
         ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC", $args), $parents);
@@ -977,7 +981,7 @@ function menu_tree_page_data($menu_name 
         // LEFT JOIN since there is no match in {menu_router} for an external
         // link.
         $data['tree'] = menu_tree_data(db_query("
-          SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.*
+          SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, m.description, m.mask, ml.*
           FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path
           WHERE ml.menu_name = '%s' AND ml.plid IN (" . $placeholders . ")
           ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC", $args), $parents);
@@ -2241,6 +2245,10 @@ function _menu_link_parents_set(&$item, 
  * Helper function to build the router table based on the data from hook_menu.
  */
 function _menu_router_build($callbacks) {
+  static $mask_map = array(
+    array('+' => '[^/]*', '%' => '\d+', '%d' => '\d+', '%c' => '\w+', '%t' => '[0-9a-zA-Z_]'),
+    array('+' => '.*', '%d' => '\d+', '%c' => '\w+', '%t' => '[0-9a-zA-Z_]', '%d+' => '[\d/]*', '%c+' => '[\w/]*', '%t+' => '[/0-9a-zA-Z_]'),
+  );
   // First pass: separate callbacks from paths, making paths ready for
   // matching. Calculate fitness, and fill some default values.
   $menu = array();
@@ -2388,24 +2396,51 @@ function _menu_router_build($callbacks) 
       'tab_root' => $path,
       'path' => $path,
     );
-
+    if (isset($item['mask'])) {
+      $mask_length = max(array_keys($item['mask']));
+      $postfix = '';
+      $mask = '';
+      $parts = $item['_parts'];
+      for ($i = 0; $i <= $mask_length; $i++) {
+        $fallback = isset($parts[$i]) ? preg_quote($parts[$i]) : '';
+        $mask_part = isset($item['mask'][$i]) ? $item['mask'][$i] : $fallback;
+        $last = ($i == $mask_length);
+        if (isset($mask_map[$last][$mask_part])) {
+          $mask_part = $mask_map[$last][$mask_part];
+        }
+        if (isset($parts[$i])) {
+          $prefix = $i ? '/' : '';
+        }
+        else {
+          // If we are past the last router path part then all the parts are
+          // optional, so we wrap them in conditional non grouping blocks.
+          $prefix = '(?:/';
+          $postfix .= ')?';
+        }
+        $mask .= $prefix . $mask_part;
+      }
+      $item['mask'] = '#^(?:'. $mask . $postfix .')$#';
+    }
+    else {
+      $item['mask'] = '|^'. str_replace('%', '\d+', preg_quote($path)) . '$|';
+    }
     $title_arguments = $item['title arguments'] ? serialize($item['title arguments']) : '';
     db_query("INSERT INTO {menu_router}
       (path, load_functions, to_arg_functions, access_callback,
       access_arguments, page_callback, page_arguments, fit,
       number_parts, tab_parent, tab_root,
       title, title_callback, title_arguments,
-      type, block_callback, description, position, weight)
+      type, block_callback, description, position, weight, mask)
       VALUES ('%s', '%s', '%s', '%s',
       '%s', '%s', '%s', %d,
       %d, '%s', '%s',
       '%s', '%s', '%s',
-      %d, '%s', '%s', '%s', %d)",
+      %d, '%s', '%s', '%s', %d, '%s')",
       $path, $item['load_functions'], $item['to_arg_functions'], $item['access callback'],
       serialize($item['access arguments']), $item['page callback'], serialize($item['page arguments']), $item['_fit'],
       $item['_number_parts'], $item['tab_parent'], $item['tab_root'],
       $item['title'], $item['title callback'], $title_arguments,
-      $item['type'], $item['block callback'], $item['description'], $item['position'], $item['weight']);
+      $item['type'], $item['block callback'], $item['description'], $item['position'], $item['weight'], $item['mask']);
   }
   // Sort the masks so they are in order of descending fit, and store them.
   $masks = array_keys($masks);

=== modified file 'index.php'
--- index.php	2007-12-26 08:46:48 +0000
+++ index.php	2008-07-31 04:10:00 +0000
@@ -14,6 +14,7 @@
 
 require_once './includes/bootstrap.inc';
 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
+menu_rebuild();
 
 $return = menu_execute_active_handler();
 

=== modified file 'modules/taxonomy/taxonomy.module'
--- modules/taxonomy/taxonomy.module	2008-07-24 16:25:17 +0000
+++ modules/taxonomy/taxonomy.module	2008-07-31 04:33:43 +0000
@@ -154,6 +154,7 @@ function taxonomy_menu() {
     'page callback' => 'taxonomy_term_page',
     'page arguments' => array(2),
     'access arguments' => array('access content'),
+    'mask' =>  array(2 => '(?:(?:(?:(?:\d+[+ ])+)|(?:(?:\d+,)*))\d+)', '%d', '(?:feed|page)'),
     'type' => MENU_CALLBACK,
   );
 

=== modified file 'modules/taxonomy/taxonomy.pages.inc'
--- modules/taxonomy/taxonomy.pages.inc	2008-04-14 17:48:33 +0000
+++ modules/taxonomy/taxonomy.pages.inc	2008-07-31 04:10:00 +0000
@@ -64,9 +64,6 @@ function taxonomy_term_page($str_tids = 
 
           node_feed($items, $channel);
           break;
-
-        default:
-          drupal_not_found();
       }
     }
     else {

