From 4d71b248ca7b7af1565988675ca02063aa5c9fb2 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Tue, 23 Aug 2016 23:14:58 -0400 Subject: [PATCH] Stop the beforeDispatch event on redirect routes. By stopping the beforeDispatch event we can ensure that a controller is not built, and that no other dispatch filters are invoked. This lets the redirect happen. Refs #9336 --- src/Routing/Filter/RoutingFilter.php | 1 + tests/TestCase/Routing/Filter/RoutingFilterTest.php | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Routing/Filter/RoutingFilter.php b/src/Routing/Filter/RoutingFilter.php index faea2cd2fa9..293f627eb84 100644 --- a/src/Routing/Filter/RoutingFilter.php +++ b/src/Routing/Filter/RoutingFilter.php @@ -58,6 +58,7 @@ public function beforeDispatch(Event $event) $request->addParams($params); } } catch (RedirectException $e) { + $event->stopPropagation(); $response = $event->data['response']; $response->statusCode($e->getCode()); $response->header('Location', $e->getMessage()); diff --git a/tests/TestCase/Routing/Filter/RoutingFilterTest.php b/tests/TestCase/Routing/Filter/RoutingFilterTest.php index b8f73c8e45b..58be6b85c25 100644 --- a/tests/TestCase/Routing/Filter/RoutingFilterTest.php +++ b/tests/TestCase/Routing/Filter/RoutingFilterTest.php @@ -90,6 +90,7 @@ public function testBeforeDispatchRedirectRoute() $this->assertInstanceOf('Cake\Network\Response', $response); $this->assertSame('http://localhost/articles', $response->header()['Location']); $this->assertSame(301, $response->statusCode()); + $this->assertTrue($event->isStopped()); } /**