Skip to content

Commit

Permalink
Don't split route params on /, only trim them before passing them int…
Browse files Browse the repository at this point in the history
…o the callback. Fixes bramus#8
  • Loading branch information
bramus committed Sep 17, 2013
1 parent 05ee027 commit 458004f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/Bramus/Router/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,7 @@ private function handle($routes, $quitAfterRun = false) {

// Extract the matched URL parameters (and only the parameters)
$params = array_map(function($match) {
$var = explode('/', trim($match, '/'));
return isset($var[0]) ? $var[0] : null;
return trim($match, '/');
}, array_slice($matches[0], 1));

// call the handling function with the URL parameters
Expand Down
38 changes: 38 additions & 0 deletions tests/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,44 @@ public function testDynamicRouteWithOptionalSubpatterns() {

}

public function testDynamicRouteWithWildcard() {

// Create Router
$router = new \Bramus\Router\Router();
$router->get('(.*)', function($name) {
echo 'Hello ' . $name;
});

// Test the /hello/bramus route
ob_start();
$_SERVER['REQUEST_URI'] = '/hello/bramus';
$router->run();
$this->assertEquals('Hello hello/bramus', ob_get_contents());

// Cleanup
ob_end_clean();

}

public function testDynamicRouteWithPartialWildcard() {

// Create Router
$router = new \Bramus\Router\Router();
$router->get('/hello/(.*)', function($name) {
echo 'Hello ' . $name;
});

// Test the /hello/bramus route
ob_start();
$_SERVER['REQUEST_URI'] = '/hello/bramus/sumarb';
$router->run();
$this->assertEquals('Hello bramus/sumarb', ob_get_contents());

// Cleanup
ob_end_clean();

}

/**
* @runInSeparateProcess
*/
Expand Down

0 comments on commit 458004f

Please sign in to comment.