Skip to content

Commit

Permalink
Merge pull request #7 from legionth/wrong-api-called
Browse files Browse the repository at this point in the history
Wrong API called if there are no dynamic values and have similiar namespace
  • Loading branch information
legionth authored Dec 3, 2018
2 parents 116443a + 3681fbe commit 6142a3a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,16 @@ private function createRestfulFunction($httpMethod, $path, $function)
$requestPathArray = explode('/', $requestPath);
$pathArray = explode('/', $path);

if (count($requestPathArray) !== count($pathArray)) {
$countRequestPathEntries = count($requestPathArray);
if ($countRequestPathEntries !== count($pathArray)) {
return $next($request);
}

if ($requestPath === $path) {
return $function($request, $next);
}

if (false === strpos($path, ':')) {
return $next($request);
}

Expand Down
19 changes: 19 additions & 0 deletions tests/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,23 @@ public function testUserDefinedCallbackIsNotUsed()
$this->assertSame('/user/list', $requestAssertion->getUri()->getPath());
$this->assertSame('example.com', $requestAssertion->getHeaderLine('Host'));
}

public function testNoSuchCallDefinedResultInNeverCalled()
{
$requestAssertion = null;
$server = new Server();

$server->get('/user/anotherlist', function (ServerRequestInterface $request, callable $next) use (&$requestAssertion) {
$requestAssertion = $request;
});

$server->get('/user/list', function (ServerRequestInterface $request, callable $next) use (&$requestAssertion) {
$requestAssertion = $request;
});

$this->socket->emit('connection', array($this->connection));
$this->connection->emit('data', array("GET http://example.com/user/anotherlista HTTP/1.0\r\n\r\n"));

$this->assertSame(null, $requestAssertion);
}
}

0 comments on commit 6142a3a

Please sign in to comment.