Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Fixes path truncation in PathMiddlewareDecorator to be case insensitive #169

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Middleware/PathMiddlewareDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private function prepareRequestWithTruncatedPrefix(ServerRequestInterface $reque
*/
private function getTruncatedPath($segment, $path)
{
if ($segment === $path) {
if (strtolower($segment) === strtolower($path)) {
// Decorated path and current path are the same; return empty string
return '';
}
Expand Down
26 changes: 26 additions & 0 deletions test/Middleware/PathMiddlewareDecoratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,30 @@ public function testUpdatesInPathInsideNestedMiddlewareAreRespected()

$this->assertSame($response, $middleware->process($request, $handler->reveal()));
}

public function testProcessesMatchedPathsWithoutCaseSensitivity()
{
$finalHandler = $this->prophesize(RequestHandlerInterface::class);
$finalHandler->{HANDLER_METHOD}(Argument::any())->willReturn(new Response());

// Note that the path requested is ALL CAPS:
$request = new ServerRequest([], [], 'http://local.example.com/MYADMIN', 'GET', 'php://memory');

$middleware = $this->prophesize(MiddlewareInterface::class);
$middleware
->process(
Argument::that(function (ServerRequestInterface $req) {
Assert::assertSame('', $req->getUri()->getPath());

return true;
}),
Argument::any()
)
->willReturn(new Response())
->shouldBeCalledTimes(1);

// Note that the path to match is lowercase:
$decorator = new PathMiddlewareDecorator('/myadmin', $middleware->reveal());
$decorator->process($request, $finalHandler->reveal());
}
}