From a15b17e08bcbe083b3400b1aa7ae388b88570bfe Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 23 Oct 2016 10:29:54 +0200 Subject: [PATCH] Fixed regression bug while processing versionning for rest paths --- module/Rest/src/Middleware/PathVersionMiddleware.php | 5 +++++ .../test/Middleware/PathVersionMiddlewareTest.php | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/module/Rest/src/Middleware/PathVersionMiddleware.php b/module/Rest/src/Middleware/PathVersionMiddleware.php index b3eae2998..ac29d9723 100644 --- a/module/Rest/src/Middleware/PathVersionMiddleware.php +++ b/module/Rest/src/Middleware/PathVersionMiddleware.php @@ -37,6 +37,11 @@ public function __invoke(Request $request, Response $response, callable $out = n $uri = $request->getUri(); $path = $uri->getPath(); + // Exclude non-rest route + if (strpos($path, '/rest') !== 0) { + return $out($request, $response); + } + // If the path does not begin with the version number, prepend v1 by default for retrocompatibility purposes if (strpos($path, '/rest/v') !== 0) { $parts = explode('/', $path); diff --git a/module/Rest/test/Middleware/PathVersionMiddlewareTest.php b/module/Rest/test/Middleware/PathVersionMiddlewareTest.php index 098c4b010..6eba4feb4 100644 --- a/module/Rest/test/Middleware/PathVersionMiddlewareTest.php +++ b/module/Rest/test/Middleware/PathVersionMiddlewareTest.php @@ -44,4 +44,16 @@ public function versionOneIsPrependedWhenNoVersionIsDefined() $this->assertEquals('/rest/v1/bar/baz', $req->getUri()->getPath()); }); } + + /** + * @test + */ + public function nonRestPathsAreNotProcessed() + { + $request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/non-rest')); + $test = $this; + $this->middleware->__invoke($request, new Response(), function ($req) use ($request, $test) { + $test->assertSame($request, $req); + }); + } }