Skip to content

Commit

Permalink
Introduce the strip argument to Router.
Browse files Browse the repository at this point in the history
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
markstory committed Jul 13, 2013
1 parent f9fdc1e commit 52be365
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Cake/Routing/Router.php
Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions lib/Cake/Test/Case/Routing/RouterTest.php
Expand Up @@ -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();
Expand Down

0 comments on commit 52be365

Please sign in to comment.