Skip to content
Permalink
Browse files

Fix incorrect path indexing for greedy routes.

Greedy routes should be indexed without the trailing /. Failing to do
that makes paths without trailing arguments fail.

Fixes #3943
  • Loading branch information...
markstory committed Jul 11, 2014
1 parent 3b7cd3d commit 20a8f2d9916279766fd863ccdbf603954acb93de
@@ -588,7 +588,8 @@ public function staticPath() {
}
$star = strpos($this->template, '*');
if ($star !== false) {
return substr($this->template, 0, $star);
$path = rtrim(substr($this->template, 0, $star), '/');
return $path === '' ? '/' : $path;
}
return $this->template;
}
@@ -582,6 +582,20 @@ public function testParse() {
$result = $route->parse('/admin/posts');
$this->assertEquals('posts', $result['controller']);
$this->assertEquals('index', $result['action']);
$route = new Route(
'/media/search/*',
['controller' => 'Media', 'action' => 'search']
);
$result = $route->parse('/media/search');
$this->assertEquals('Media', $result['controller']);
$this->assertEquals('search', $result['action']);
$this->assertEquals([], $result['pass']);
$result = $route->parse('/media/search/tv/shows');
$this->assertEquals('Media', $result['controller']);
$this->assertEquals('search', $result['action']);
$this->assertEquals(['tv', 'shows'], $result['pass']);
}
/**
@@ -941,8 +955,11 @@ public function testUTF8PatternOnSection() {
* @return void
*/
public function testStaticPath() {
$route = new Route('/*', ['controller' => 'Pages', 'action' => 'display']);
$this->assertEquals('/', $route->staticPath());
$route = new Route('/pages/*', ['controller' => 'Pages', 'action' => 'display']);
$this->assertEquals('/pages/', $route->staticPath());
$this->assertEquals('/pages', $route->staticPath());
$route = new Route('/pages/:id/*', ['controller' => 'Pages', 'action' => 'display']);
$this->assertEquals('/pages/', $route->staticPath());
@@ -56,6 +56,7 @@ public function testParse() {
$routes = new RouteBuilder($this->collection, '/b', ['key' => 'value']);
$routes->connect('/', ['controller' => 'Articles']);
$routes->connect('/:id', ['controller' => 'Articles', 'action' => 'view']);
$routes->connect('/media/search/*', ['controller' => 'Media', 'action' => 'search']);
$result = $this->collection->parse('/b/');
$expected = [
@@ -78,6 +79,26 @@ public function testParse() {
'?' => ['one' => 'two'],
];
$this->assertEquals($expected, $result);
$result = $this->collection->parse('/b/media/search');
$expected = [
'key' => 'value',
'pass' => [],
'plugin' => null,
'controller' => 'Media',
'action' => 'search'
];
$this->assertEquals($expected, $result);
$result = $this->collection->parse('/b/media/search/thing');
$expected = [
'key' => 'value',
'pass' => ['thing'],
'plugin' => null,
'controller' => 'Media',
'action' => 'search'
];
$this->assertEquals($expected, $result);
}
/**
@@ -1990,7 +1990,6 @@ public function testParsingWithLiteralPrefixes() {
Router::reload();
$adminParams = array('prefix' => 'admin');
Router::connect('/admin/:controller', $adminParams);
Router::connect('/admin/:controller/:action', $adminParams);
Router::connect('/admin/:controller/:action/*', $adminParams);
$request = new Request();

0 comments on commit 20a8f2d

Please sign in to comment.
You can’t perform that action at this time.