Merge pull request #15181 from cakephp/fix-15163

Fix incorrect URL generation
This commit is contained in:
Mark Story 2020-11-30 10:38:21 -05:00 committed by GitHub
commit 1c27b82b49
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View file

@ -256,7 +256,10 @@ class CakeRequest implements ArrayAccess {
if ($qPosition !== false && strpos($_SERVER['REQUEST_URI'], '://') > $qPosition) {
$uri = $_SERVER['REQUEST_URI'];
} 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'])) {
$uri = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['PHP_SELF']);

View file

@ -215,9 +215,14 @@ class CakeRequestTest extends CakeTestCase {
$request = new CakeRequest();
$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();
$this->assertEquals('other/path', $request->url);
$_SERVER['REQUEST_URI'] = str_repeat('x', strlen($base) - 4) . '://?/other/path';
$request = new CakeRequest();
$this->assertEquals('', $request->url);
}
/**