mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Add missing urlencoding to base/webroot.
This fixes URL generation when PHP_SELF or the request path contains special characters.
This commit is contained in:
parent
f745a02210
commit
6017db9dc8
4 changed files with 22 additions and 6 deletions
|
@ -292,7 +292,7 @@ class CakeRequest implements ArrayAccess {
|
|||
if ($base === DS || $base === '.') {
|
||||
$base = '';
|
||||
}
|
||||
|
||||
$base = implode('/', array_map('rawurlencode', explode('/', $base)));
|
||||
$this->webroot = $base . '/';
|
||||
return $this->base = $base;
|
||||
}
|
||||
|
|
|
@ -1100,6 +1100,15 @@ class CakeRequestTest extends CakeTestCase {
|
|||
public function testBaseUrlAndWebrootWithModRewrite() {
|
||||
Configure::write('App.baseUrl', false);
|
||||
|
||||
$_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches';
|
||||
$_SERVER['PHP_SELF'] = '/urlencode me/app/webroot/index.php';
|
||||
$_SERVER['PATH_INFO'] = '/posts/view/1';
|
||||
|
||||
$request = new CakeRequest();
|
||||
$this->assertEquals('/urlencode%20me', $request->base);
|
||||
$this->assertEquals('/urlencode%20me/', $request->webroot);
|
||||
$this->assertEquals('posts/view/1', $request->url);
|
||||
|
||||
$_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches';
|
||||
$_SERVER['PHP_SELF'] = '/1.2.x.x/app/webroot/index.php';
|
||||
$_SERVER['PATH_INFO'] = '/posts/view/1';
|
||||
|
|
|
@ -605,6 +605,10 @@ class HelperTest extends CakeTestCase {
|
|||
|
||||
Configure::write('Asset.timestamp', true);
|
||||
Configure::write('debug', 0);
|
||||
|
||||
$result = $this->Helper->assetTimestamp('/%3Cb%3E/cake.generic.css');
|
||||
$this->assertEquals('/%3Cb%3E/cake.generic.css', $result);
|
||||
|
||||
$result = $this->Helper->assetTimestamp(CSS_URL . 'cake.generic.css');
|
||||
$this->assertEquals(CSS_URL . 'cake.generic.css', $result);
|
||||
|
||||
|
|
|
@ -341,10 +341,9 @@ class Helper extends Object {
|
|||
*/
|
||||
protected function _encodeUrl($url) {
|
||||
$path = parse_url($url, PHP_URL_PATH);
|
||||
$encoded = implode('/', array_map(
|
||||
'rawurlencode',
|
||||
explode('/', $path)
|
||||
));
|
||||
$parts = array_map('urldecode', explode('/', $path));
|
||||
$parts = array_map('rawurlencode', $parts);
|
||||
$encoded = implode('/', $parts);
|
||||
return h(str_replace($path, $encoded, $url));
|
||||
}
|
||||
|
||||
|
@ -360,7 +359,11 @@ class Helper extends Object {
|
|||
$stamp = Configure::read('Asset.timestamp');
|
||||
$timestampEnabled = $stamp === 'force' || ($stamp === true && Configure::read('debug') > 0);
|
||||
if ($timestampEnabled && strpos($path, '?') === false) {
|
||||
$filepath = preg_replace('/^' . preg_quote($this->request->webroot, '/') . '/', '', $path);
|
||||
$filepath = preg_replace(
|
||||
'/^' . preg_quote($this->request->webroot, '/') . '/',
|
||||
'',
|
||||
urldecode($path)
|
||||
);
|
||||
$webrootPath = WWW_ROOT . str_replace('/', DS, $filepath);
|
||||
if (file_exists($webrootPath)) {
|
||||
//@codingStandardsIgnoreStart
|
||||
|
|
Loading…
Reference in a new issue