Skip to content

Commit

Permalink
Fix routes not matching without trailing /
Browse files Browse the repository at this point in the history
Routes connected in scopes should match both the / and non / terminated
URLs.

Refs #4218
  • Loading branch information
markstory committed Aug 11, 2014
1 parent 084651d commit 6ebfd74
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Routing/RouteBuilder.php
Expand Up @@ -346,6 +346,8 @@ protected function _makeRoute($route, $defaults, $options) {
unset($options['routeClass']);

$route = str_replace('//', '/', $this->_path . $route);
$route = $route === '/' ? $route : rtrim($route, '/');

foreach ($this->_params as $param => $val) {
if (isset($defaults[$param]) && $defaults[$param] !== $val) {
$msg = 'You cannot define routes that conflict with the scope. ' .
Expand Down
14 changes: 14 additions & 0 deletions tests/TestCase/Routing/RouteBuilderTest.php
Expand Up @@ -112,6 +112,20 @@ public function testConnectBasic() {
$this->assertEquals($expected, $route->defaults);
}

/**
* Test that compiling a route results in an trailing / optional pattern.
*
* @return void
*/
public function testConnectTrimTrailingSlash() {
$routes = new RouteBuilder($this->collection, '/articles', ['controller' => 'Articles']);
$routes->connect('/', ['action' => 'index']);

$expected = ['plugin' => null, 'controller' => 'Articles', 'action' => 'index', 'pass' => []];
$this->assertEquals($expected, $this->collection->parse('/articles'));
$this->assertEquals($expected, $this->collection->parse('/articles/'));
}

/**
* Test extensions being connected to routes.
*
Expand Down

0 comments on commit 6ebfd74

Please sign in to comment.