Skip to content

Commit

Permalink
Correctly handle leading slashes on routes add. Fixes #322
Browse files Browse the repository at this point in the history
  • Loading branch information
lonnieezell committed Jan 5, 2017
1 parent 43de1a0 commit a9c6cff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion system/Router/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ protected function create(string $from, $to, array $options = null)
// it doens't work with matching, so remove them...
if ($from != '/')
{
$from = rtrim($from, '/');
$from = trim($from, '/');
}

if (is_null($options))
Expand Down
17 changes: 17 additions & 0 deletions tests/system/Router/RouteCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@ public function testAddWorksWithCurrentHTTPMethods()

//--------------------------------------------------------------------

public function testAddWithLeadingSlash()
{
$routes = new RouteCollection();

$routes->add('/home', 'controller');

$expects = [
'home' => '\controller',
];

$routes = $routes->getRoutes();

$this->assertEquals($expects, $routes);
}

//--------------------------------------------------------------------

public function testMatchIgnoresInvalidHTTPMethods()
{
$_SERVER['REQUEST_METHOD'] = 'GET';
Expand Down

0 comments on commit a9c6cff

Please sign in to comment.