From 992164446cf7da39078d879300475b6353e1d40f Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 16 Feb 2015 16:26:02 +0100 Subject: [PATCH] Add blackmagic due to cyclic dependency :see_no_evil: --- lib/base.php | 9 ++++++++- lib/private/appframework/http/request.php | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/base.php b/lib/base.php index 51d59d130a..5905aa0406 100644 --- a/lib/base.php +++ b/lib/base.php @@ -104,7 +104,14 @@ class OC { * FIXME: The following line is required because of a cyclic dependency * on IRequest. */ - $scriptName = $_SERVER['SCRIPT_NAME']; + $params = [ + 'server' => [ + 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], + 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'], + ], + ]; + $fakeRequest = new \OC\AppFramework\Http\Request($params, null, new \OC\AllConfig(new \OC\SystemConfig())); + $scriptName = $fakeRequest->getScriptName(); if (substr($scriptName, -1) == '/') { $scriptName .= 'index.php'; //make sure suburi follows the same rules as scriptName diff --git a/lib/private/appframework/http/request.php b/lib/private/appframework/http/request.php index 97e9809c1f..5cffbccb62 100644 --- a/lib/private/appframework/http/request.php +++ b/lib/private/appframework/http/request.php @@ -80,7 +80,7 @@ class Request implements \ArrayAccess, \Countable, IRequest { * @see http://www.php.net/manual/en/reserved.variables.php */ public function __construct(array $vars=array(), - ISecureRandom $secureRandom, + ISecureRandom $secureRandom = null, IConfig $config, $stream='php://input') { $this->inputStream = $stream; @@ -596,8 +596,8 @@ class Request implements \ArrayAccess, \Countable, IRequest { $name = $this->server['SCRIPT_NAME']; $overwriteWebRoot = $this->config->getSystemValue('overwritewebroot'); if ($overwriteWebRoot !== '' && $this->isOverwriteCondition()) { - // FIXME: This code is untestable due to ___DIR__ - $serverRoot = str_replace('\\', '/', substr(__DIR__, 0, -strlen('lib/private/'))); + // FIXME: This code is untestable due to __DIR__, also that hardcoded path is really dangerous + $serverRoot = str_replace('\\', '/', substr(__DIR__, 0, -strlen('lib/private/appframework/http/'))); $suburi = str_replace('\\', '/', substr(realpath($this->server['SCRIPT_FILENAME']), strlen($serverRoot))); $name = '/' . ltrim($overwriteWebRoot . $suburi, '/'); }