Skip to content

Commit

Permalink
Stop the beforeDispatch event on redirect routes.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
markstory committed Aug 24, 2016
1 parent 68dcf5d commit 4d71b24
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Routing/Filter/RoutingFilter.php
Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions tests/TestCase/Routing/Filter/RoutingFilterTest.php
Expand Up @@ -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());
}

/**
Expand Down

0 comments on commit 4d71b24

Please sign in to comment.