Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2022-04-07 15:08:37 +0300
committerJoas Schilling <coding@schilljs.com>2022-04-07 15:08:37 +0300
commita06ba8850243b93295e9c49ab820c0c46d9b220a (patch)
tree8c333d355de2bff158377fb871cefd2c176a1db8 /lib
parent0e29dc8c76a379b7f34f63303ae831e52bb62801 (diff)
Fix \OC_App::getCurrentApp() when being called from CLI or phpunit
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/legacy/OC_App.php11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php
index ca01e91216b..245bfe76d98 100644
--- a/lib/private/legacy/OC_App.php
+++ b/lib/private/legacy/OC_App.php
@@ -629,11 +629,20 @@ class OC_App {
* @return string
*/
public static function getCurrentApp(): string {
+ if (\OC::$CLI) {
+ return '';
+ }
+
$request = \OC::$server->getRequest();
$script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1);
$topFolder = substr($script, 0, strpos($script, '/') ?: 0);
if (empty($topFolder)) {
- $path_info = $request->getPathInfo();
+ try {
+ $path_info = $request->getPathInfo();
+ } catch (Exception $e) {
+ // Can happen from unit tests because the script name is `./vendor/bin/phpunit` or something a like then.
+ return '';
+ }
if ($path_info) {
$topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1);
}