mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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
This commit is contained in:
parent
f9fdc1e6e0
commit
52be365598
2 changed files with 5 additions and 2 deletions
|
@ -1053,7 +1053,7 @@ class Router {
|
|||
* @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 @@ class Router {
|
|||
}
|
||||
$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 @@ class RouterTest extends CakeTestCase {
|
|||
$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();
|
||||
|
|
Loading…
Reference in a new issue