From a2aebdb03f98f31077925112c2c51f561563c2e6 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 27 Oct 2011 10:48:54 -0500 Subject: [PATCH] fix routing provides bug. --- laravel/routing/router.php | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/laravel/routing/router.php b/laravel/routing/router.php index 718fede2..938234f0 100644 --- a/laravel/routing/router.php +++ b/laravel/routing/router.php @@ -123,14 +123,13 @@ public function route($method, $uri, $format) foreach ($routes as $keys => $callback) { - // We need to make sure that the requested format is provided by the - // route. If it isn't, there is no need to continue evaluating it. - if ( ! in_array($format, $this->provides($callback))) continue; + $formats = $this->formats($callback); - // Only check routes having multiple URIs or wildcards since other - // routes would have been caught by the check for literal matches. - if (strpos($keys, '(') !== false or strpos($keys, ',') !== false) + // Only check the routes that couldn't be matched literally... + if (($format_count = count($formats)) > 0 or $this->fuzzy($keys)) { + if ($format_count > 0 and ! in_array($format, $formats)) continue; + if ( ! is_null($route = $this->match($destination, $keys, $callback, $format))) { return Request::$route = $route; @@ -147,14 +146,29 @@ public function route($method, $uri, $format) * @param mixed $callback * @return array */ - protected function provides($callback) + protected function formats($callback) { if (is_array($callback) and isset($callback['provides'])) { return (is_string($provides = $callback['provides'])) ? explode('|', $provides) : $provides; } - return array('html'); + return array(); + } + + /** + * Determine if a route needs to be examined using a regular expression. + * + * Routes that contain wildcards or multiple URIs cannot be matched using + * a literal key check on the array. The wildcards will have to be turned + * into real regular expressions and the multiple URIs have to be split. + * + * @param string $keys + * @return bool + */ + protected function fuzzy($keys) + { + return strpos($keys, '(') !== false or strpos($keys, ',') !== false; } /**