Skip to content

Commit

Permalink
Fix query string handling in routing
Browse files Browse the repository at this point in the history
  • Loading branch information
maikgreubel committed Aug 15, 2017
1 parent 8f2ae0f commit 8e5f4c1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Mvc/Router/AbstractRouter.php
Expand Up @@ -71,13 +71,21 @@ public function route(string $name, Request $request)
$found = false;
for($i = 0; $i < count($parts); $i++) {
if($parts[$i] === $name && isset($parts[$i+1])) {
$request->setAction($parts[$i+1]);
$action = $parts[$i+1];
if(strpos($action, "?")) {
$action = strstr($action, "?");
}

$request->setAction($action);
$found = true;
}
}
if(!$found) {
$request->setAction("index");
}
return $this->getRoute($name);
$controller = $this->getRoute($name);
$request->setController($controller->getControllerSimpleName());

return $controller;
}
}
12 changes: 12 additions & 0 deletions tests/router-test/RoutingTest.php
Expand Up @@ -34,6 +34,18 @@ public function testRouting()
$this->assertEquals(0, count($request->getParams()));
$this->assertEquals('/routingTest/routed', $request->getOrigin());
$this->assertContains("flex'd", $response->getBody());
}

public function testRoutingInclQueryString()
{
$request = Request::parse("/routingTest/routed?id=25&quote=ent");

$response = Application::getInstance()->serve('default', array(), $request, false);

$this->assertEquals('Routed', $request->getController());
$this->assertEquals('index', $request->getAction());
$this->assertEquals(2, count($request->getParams()));
$this->assertEquals('/routingTest/routed?id=25&quote=ent', $request->getOrigin());
$this->assertContains("flex'd", $response->getBody());
}
}

0 comments on commit 8e5f4c1

Please sign in to comment.