Skip to content

Commit

Permalink
Fix trailing / present when extensions were used.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jul 4, 2012
1 parent 1dac947 commit e1db220
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/Cake/Routing/Route/Route.php
Expand Up @@ -495,11 +495,13 @@ protected function _writeUrl($params, $pass = array(), $query = array()) {
$out
);
}
if (!empty($params['_ext']) || !empty($query)) {
$out = rtrim($out, '/');
}
if (!empty($params['_ext'])) {
$out .= '.' . $params['_ext'];
}
if (!empty($query)) {
$out = rtrim($out, '/');
$out .= '?' . http_build_query($query);
}
return $out;
Expand Down
16 changes: 16 additions & 0 deletions lib/Cake/Test/TestCase/Routing/Route/RouteTest.php
Expand Up @@ -436,6 +436,22 @@ public function testMatchWithExtension() {
'_ext' => 'json'
));
$this->assertEquals('/posts/index.json', $result);

$route = new Route('/:controller/:action/*');
$result = $route->match(array(
'controller' => 'posts',
'action' => 'index',
'_ext' => 'json',
));
$this->assertEquals('/posts/index.json', $result);

$result = $route->match(array(
'controller' => 'posts',
'action' => 'view',
1,
'_ext' => 'json',
));
$this->assertEquals('/posts/view/1.json', $result);
}

/**
Expand Down

0 comments on commit e1db220

Please sign in to comment.