Skip to content

Commit

Permalink
Append / to the start/end of the mapResources prefix.
Browse files Browse the repository at this point in the history
This makes the method easier to use and less error prone.

Fixes #2431
  • Loading branch information
markstory committed Dec 5, 2013
1 parent 58317d3 commit 85a9132
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Cake/Routing/Router.php
Expand Up @@ -503,6 +503,12 @@ public static function mapResources($controller, $options = array()) {
), $options);

$prefix = $options['prefix'];
if (strpos($prefix, '/') !== 0) {
$prefix = '/' . $prefix;
}
if (substr($prefix, -1) !== '/') {
$prefix .= '/';
}

foreach ((array)$controller as $name) {
list($plugin, $name) = pluginSplit($name);
Expand Down
14 changes: 14 additions & 0 deletions lib/Cake/Test/Case/Routing/RouterTest.php
Expand Up @@ -215,6 +215,20 @@ public function testPluginMapResourcesWithPrefix() {
);
$this->assertEquals($expected, $result);
$this->assertEquals(array('test_plugin'), $resources);

$resources = Router::mapResources('Posts', array('prefix' => 'api'));

$_SERVER['REQUEST_METHOD'] = 'GET';
$result = Router::parse('/api/posts');
$expected = array(
'pass' => array(),
'named' => array(),
'plugin' => null,
'controller' => 'posts',
'action' => 'index',
'[method]' => 'GET'
);
$this->assertEquals($expected, $result);
}

/**
Expand Down

0 comments on commit 85a9132

Please sign in to comment.