Browse Source

fix bug in route handles method.

Taylor Otwell 13 years ago
parent
commit
9bcbe6a357
2 changed files with 5 additions and 4 deletions
  1. 2 2
      laravel/routing/route.php
  2. 3 2
      tests/cases/laravel/route.test.php

+ 2 - 2
laravel/routing/route.php

@@ -214,11 +214,11 @@ class Route {
 	 */
 	public function handles($uri)
 	{
-		$pattern = '#'.str_replace('*', '(.*)', $uri).'#';
+		$pattern = ($uri !== '/') ? str_replace('*', '(.*)', $uri) : '^/$';
 
 		return ! is_null(array_first($this->uris, function($key, $uri) use ($pattern)
 		{
-			return preg_match($pattern, $uri);
+			return preg_match('#'.$pattern.'#', $uri);
 		}));
 	}
 

+ 3 - 2
tests/cases/laravel/route.test.php

@@ -19,10 +19,11 @@ class RouteTest extends PHPUnit_Framework_TestCase {
 	{
 		$route = new Laravel\Routing\Route('GET /', array('handles' => array('GET /foo/bar')));
 
-		$this->assertFalse($route->handles('/'));
-		$this->assertFalse($route->handles('baz'));
 		$this->assertTrue($route->handles('foo/*'));
 		$this->assertTrue($route->handles('foo/bar'));
+		$this->assertFalse($route->handles('/'));
+		$this->assertFalse($route->handles('baz'));
+		$this->assertFalse($route->handles('/foo'));
 
 		$route = new Laravel\Routing\Route('GET /', array('handles' => array('GET /', 'GET /home')));