Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

RedirectRoute class does not honor persist as array with custom route…

… elements.

Custom route elements like '/:lang/etc' should be persisted by redirect
routes as they are in standard routes.

Refs #GH-1531
  • Loading branch information...
commit 7fe2395be3ee21a2e1203dec968ab58d84140621 1 parent 8428928
joostdekeijzer authored markstory committed
View
7 lib/Cake/Routing/Route/RedirectRoute.php
@@ -80,6 +80,13 @@ public function parse($url) {
}
if (isset($this->options['persist']) && is_array($redirect)) {
$redirect += array('named' => $params['named'], 'pass' => $params['pass'], 'url' => array());
+ if (is_array($this->options['persist'])) {
+ foreach ($this->options['persist'] as $elem) {
+ if (isset($params[$elem])) {
+ $redirect[$elem] = $params[$elem];
+ }
+ }
+ }
$redirect = Router::reverse($redirect);
}
$status = 301;
View
16 lib/Cake/Test/Case/Routing/Route/RedirectRouteTest.php
@@ -103,6 +103,22 @@ public function testParsing() {
$result = $route->parse('/my_controllers/do_something/passme/named:param');
$header = $route->response->header();
$this->assertEquals(Router::url('/tags/add', true), $header['Location']);
+
+ $route = new RedirectRoute('/:lang/my_controllers', array('controller' => 'tags', 'action' => 'add'), array('lang' => '(nl|en)', 'persist' => array('lang')));
+ $route->stop = false;
+ $route->response = $this->getMock('CakeResponse', array('_sendHeader'));
+ $result = $route->parse('/nl/my_controllers/');
+ $header = $route->response->header();
+ $this->assertEquals(Router::url('/tags/add/lang:nl', true), $header['Location']);
+
+ Router::$routes = array(); // reset default routes
+ Router::connect('/:lang/preferred_controllers', array('controller' => 'tags', 'action' => 'add'), array('lang' => '(nl|en)', 'persist' => array('lang')));
+ $route = new RedirectRoute('/:lang/my_controllers', array('controller' => 'tags', 'action' => 'add'), array('lang' => '(nl|en)', 'persist' => array('lang')));
+ $route->stop = false;
+ $route->response = $this->getMock('CakeResponse', array('_sendHeader'));
+ $result = $route->parse('/nl/my_controllers/');
+ $header = $route->response->header();
+ $this->assertEquals(Router::url('/nl/preferred_controllers', true), $header['Location']);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.