mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fix incorrect URL generation
When a fullBaseURL is being used we should check for the exact base string being a prefix and not just the string length as it could be full of garbage. Fixes #15163
This commit is contained in:
parent
b07bba4d4f
commit
63d708118a
2 changed files with 10 additions and 2 deletions
|
@ -256,7 +256,10 @@ class CakeRequest implements ArrayAccess {
|
||||||
if ($qPosition !== false && strpos($_SERVER['REQUEST_URI'], '://') > $qPosition) {
|
if ($qPosition !== false && strpos($_SERVER['REQUEST_URI'], '://') > $qPosition) {
|
||||||
$uri = $_SERVER['REQUEST_URI'];
|
$uri = $_SERVER['REQUEST_URI'];
|
||||||
} else {
|
} else {
|
||||||
$uri = substr($_SERVER['REQUEST_URI'], strlen(Configure::read('App.fullBaseUrl')));
|
$baseUrl = Configure::read('App.fullBaseUrl');
|
||||||
|
if (substr($_SERVER['REQUEST_URI'], 0, strlen($baseUrl)) === $baseUrl) {
|
||||||
|
$uri = substr($_SERVER['REQUEST_URI'], strlen($baseUrl));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} elseif (isset($_SERVER['PHP_SELF']) && isset($_SERVER['SCRIPT_NAME'])) {
|
} elseif (isset($_SERVER['PHP_SELF']) && isset($_SERVER['SCRIPT_NAME'])) {
|
||||||
$uri = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['PHP_SELF']);
|
$uri = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['PHP_SELF']);
|
||||||
|
|
|
@ -215,9 +215,14 @@ class CakeRequestTest extends CakeTestCase {
|
||||||
$request = new CakeRequest();
|
$request = new CakeRequest();
|
||||||
$this->assertEquals('some/path', $request->url);
|
$this->assertEquals('some/path', $request->url);
|
||||||
|
|
||||||
$_SERVER['REQUEST_URI'] = Configure::read('App.fullBaseUrl') . '/other/path?url=https://cakephp.org';
|
$base = Configure::read('App.fullBaseUrl');
|
||||||
|
$_SERVER['REQUEST_URI'] = $base . '/other/path?url=https://cakephp.org';
|
||||||
$request = new CakeRequest();
|
$request = new CakeRequest();
|
||||||
$this->assertEquals('other/path', $request->url);
|
$this->assertEquals('other/path', $request->url);
|
||||||
|
|
||||||
|
$_SERVER['REQUEST_URI'] = str_repeat('x', strlen($base) - 4) . '://?/other/path';
|
||||||
|
$request = new CakeRequest();
|
||||||
|
$this->assertEquals('', $request->url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue