Skip to content

Commit

Permalink
Fix incorrect staticPath() generation for brace style routes.
Browse files Browse the repository at this point in the history
Brace style routes were not correctly generating their static path
prefix. This resulted in routes not being found during URL parsing.
  • Loading branch information
markstory committed Jun 12, 2018
1 parent 2482145 commit 9d2b24e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Routing/Route/Route.php
Expand Up @@ -866,6 +866,10 @@ public function staticPath()
if ($routeKey !== false) {
return substr($this->template, 0, $routeKey);
}
$routeKey = strpos($this->template, '{');
if ($routeKey !== false && strpos($this->template, '}') !== false) {
return substr($this->template, 0, $routeKey);
}
$star = strpos($this->template, '*');
if ($star !== false) {
$path = rtrim(substr($this->template, 0, $star), '/');
Expand Down
20 changes: 20 additions & 0 deletions tests/TestCase/Routing/Route/RouteTest.php
Expand Up @@ -1728,6 +1728,26 @@ public function testStaticPath()
$route = new Route('/:controller/:action/*');
$this->assertEquals('/', $route->staticPath());

$route = new Route('/api/{/:action/*');
$this->assertEquals('/api/{/', $route->staticPath());

$route = new Route('/books/reviews', ['controller' => 'Reviews', 'action' => 'index']);
$this->assertEquals('/books/reviews', $route->staticPath());
}

/**
* Test getting the static path for a route.
*
* @return void
*/
public function testStaticPathBrace()
{
$route = new Route('/pages/{id}/*', ['controller' => 'Pages', 'action' => 'display']);
$this->assertEquals('/pages/', $route->staticPath());

$route = new Route('/{controller}/{action}/*');
$this->assertEquals('/', $route->staticPath());

$route = new Route('/books/reviews', ['controller' => 'Reviews', 'action' => 'index']);
$this->assertEquals('/books/reviews', $route->staticPath());
}
Expand Down

0 comments on commit 9d2b24e

Please sign in to comment.