Numeric menu paths (e.g. /404, /403) don't work.

function foo_menu() {
  $items = array();

  $items['403'] = array(
    'title' => 'Access denied',
    'page callback' => 'error_pages__error_page_403',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  return $items;
}

With the code example above, an entry goes into the menu_router table with the path 0 (instead of the path 403).

This is because the router-building functions menu_router_build and _menu_router_build build an array structure where the path is the menu-key, and use array-handling functions which do not preserve numeric keys (i.e. array_merge and array_multisort.

E.g. within menu_router_build:

  foreach (module_implements('menu') as $module) {
    $router_items = call_user_func($module . '_menu');
    if (isset($router_items) && is_array($router_items)) {
      foreach (array_keys($router_items) as $path) {
        $router_items[$path]['module'] = $module;
      }
      $callbacks = array_merge($callbacks, $router_items);
    }

This could be solved in menu_router_build:

-      $callbacks = array_merge($callbacks, $router_items);
+      $callbacks = $callbacks + $router_items;

However, _menu_router_build uses array_multisort in a few places, which would require more thought (perhaps writing a drupal-specific version of array_multisort, which preserves numeric keys?)

Comments

alexweber’s picture

Confirmed. There is also nothing in the hook_menu() documentation to suggest that numeric paths are not allowed, therefore there is nothing wrong with the path "403" and it should work as expected.

catch’s picture

Version: 7.x-dev » 8.x-dev
Category: bug » task
Issue tags: +Needs backport to D7

This is at best an oversight, not a bug.

sun’s picture

Title: Numeric menu paths don't work » Support for top-level, numeric menu paths
Category: task » feature
Priority: Major » Normal
Issue tags: -Needs backport to D7
manarth’s picture

Version: 8.x-dev » 7.x-dev
Category: feature » bug

I disagree, it's clearly a bug. There's no mention in the docs or code to say that paths must not be numeric; maybe this hasn't worked previously, but that doesn't imply that numeric paths is a new feature.

However, I shall hold off further comment until I've got a patch!

sun’s picture

Version: 7.x-dev » 8.x-dev
Issue tags: +Needs backport to D7

AFAIK, this is not supported as it implies a quite heavy slowdown in performance. I'm pretty sure there are existing issues on d.o containing the detailed history.

jonathan_hunt’s picture

I just ran into this issue building a new site in D7 that requires numeric paths. I'm working around this by prefixing my menu router entries and aliasing them (e.g. 78 -> aliased to somestring/78). It seems to me to be a bug that Drupal's menu building won't honour numeric paths but the alias handling will.

I've scanned the Drupal core issue queue and can't see any issues relating to this (searched using "numeric paths", though #512962: Optimize menu_router_build() / _menu_router_save() discusses menu building performance *in general*).

It would be good to check now whether the Drupal 8 routing system will handle numeric paths. It would be good if Drupal as a project committed to handling any valid path per RFC 2396 (http://www.rfc-editor.org/rfc/rfc2396.txt).

alexweber’s picture

@sun regarding the performance hit, since the menu is almost always served from cache this shouldn't matter that much!

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Anonymous’s picture

Status: Active » Needs review

Now numeric path works perfect. After #2107533: Remove {menu_router} we have not menu_router_build and _menu_router_build. May be to close this issue, or move back to d7?

Looks like d7 already has issue about performance #512962: Optimize menu_router_build() / _menu_router_save() (if we want to move by #5).

Anonymous’s picture

Version: 8.4.x-dev » 7.x-dev
poker10’s picture

Status: Needs review » Closed (duplicate)
Issue tags: -Needs backport to D7
Related issues: +#2456193: Menu links - not possible to create numeric paths

This should be a duplicate of #2456193: Menu links - not possible to create numeric paths. This issue already has patch and some progress.