Skip to content

Commit

Permalink
Check for both halves of the brace.
Browse files Browse the repository at this point in the history
Only checking for one makes it possible to enter brace mode
accidentally.
  • Loading branch information
markstory committed Jan 8, 2018
1 parent d0e8f2d commit f018dbf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Routing/Route/Route.php
Expand Up @@ -322,7 +322,7 @@ protected function _writeRoute()
$names = $routeParams = [];
$parsed = preg_quote($this->template, '#');

if (strpos($route, '{') !== false) {
if (strpos($route, '{') !== false && strpos($route, '}') !== false) {
preg_match_all('/\{([a-z0-9-_]+)\}/i', $route, $namedElements);
$this->braceKeys = true;
} else {
Expand Down
13 changes: 13 additions & 0 deletions tests/TestCase/Routing/Route/RouteTest.php
Expand Up @@ -190,6 +190,19 @@ public function testRouteCompileBraces()
*/
public function testRouteCompileMixedPlaceholders()
{
$route = new Route(
'/images/{open/:id',
['controller' => 'Images', 'action' => 'open']
);
$pattern = $route->compile();
$this->assertRegExp($pattern, '/images/{open/9', 'Need both {} to enable brace mode');
$result = $route->match([
'controller' => 'Images',
'action' => 'open',
'id' => 123,
]);
$this->assertEquals('/images/{open/123', $result);

$route = new Route(
'/fighters/{id}/move/{x}/:y',
['controller' => 'Fighters', 'action' => 'move'],
Expand Down

0 comments on commit f018dbf

Please sign in to comment.