Browse Source

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
Mark Story 9 years ago
parent
commit
4d71b248ca

+ 1 - 0
src/Routing/Filter/RoutingFilter.php

@@ -58,6 +58,7 @@ class RoutingFilter extends DispatcherFilter
                 $request->addParams($params);
             }
         } catch (RedirectException $e) {
+            $event->stopPropagation();
             $response = $event->data['response'];
             $response->statusCode($e->getCode());
             $response->header('Location', $e->getMessage());

+ 1 - 0
tests/TestCase/Routing/Filter/RoutingFilterTest.php

@@ -90,6 +90,7 @@ class RoutingFilterTest extends TestCase
         $this->assertInstanceOf('Cake\Network\Response', $response);
         $this->assertSame('http://localhost/articles', $response->header()['Location']);
         $this->assertSame(301, $response->statusCode());
+        $this->assertTrue($event->isStopped());
     }
 
     /**