Permalink
Browse files

Introduce the `strip` argument to Router.

This allows callers to request that the basepath *not* be stripped off
when normalizing string URL's. This is important in AuthComponent when
handling redirect URL's as the redirect location could point to
a controller that shares a name with the base path.

Refs #3897
Refs #3916
  • Loading branch information...
1 parent f9fdc1e commit 52be365598e64d3f7178475a3a3f0f46245c70e3 @markstory markstory committed Jul 13, 2013
Showing with 5 additions and 2 deletions.
  1. +2 −2 lib/Cake/Routing/Router.php
  2. +3 −0 lib/Cake/Test/Case/Routing/RouterTest.php
@@ -1053,7 +1053,7 @@ public static function reverse($params, $full = false) {
* @param array|string $url URL to normalize Either an array or a string URL.
* @return string Normalized URL
*/
- public static function normalize($url = '/') {
+ public static function normalize($url = '/', $strip = true) {
if (is_array($url)) {
$url = Router::url($url);
}
@@ -1062,7 +1062,7 @@ public static function normalize($url = '/') {
}
$request = Router::getRequest();
- if (!empty($request->base) && stristr($url, $request->base)) {
+ if ($strip && !empty($request->base) && stristr($url, $request->base)) {
$url = preg_replace('/^' . preg_quote($request->base, '/') . '/', '', $url, 1);
}
$url = '/' . $url;
@@ -284,6 +284,9 @@ public function testUrlNormalization() {
$result = Router::normalize('/us/users/logout/');
$this->assertEquals('/users/logout', $result);
+ $result = Router::normalize('/us/users/logout/', false);
+ $this->assertEquals('/us/users/logout', $result);
+
Router::reload();
$request = new CakeRequest();

0 comments on commit 52be365

Please sign in to comment.