diff --git a/src/Middleware/PathMiddlewareDecorator.php b/src/Middleware/PathMiddlewareDecorator.php index e360aa2..327a855 100644 --- a/src/Middleware/PathMiddlewareDecorator.php +++ b/src/Middleware/PathMiddlewareDecorator.php @@ -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 ''; } diff --git a/test/Middleware/PathMiddlewareDecoratorTest.php b/test/Middleware/PathMiddlewareDecoratorTest.php index 58cee22..476cafd 100644 --- a/test/Middleware/PathMiddlewareDecoratorTest.php +++ b/test/Middleware/PathMiddlewareDecoratorTest.php @@ -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()); + } }