summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonas Meurer <jonas@freesources.org>2021-08-10 11:06:24 +0200
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2021-08-16 13:12:00 +0000
commit55fcffd11a02c3c9c75923e7912ee952bf348cab (patch)
treed78bf30d61d85edb6500b4f3db309764b84943b4
parent57e20ed566136581756a80e07995bb25f72bbcf6 (diff)
downloadnextcloud-server-55fcffd11a02c3c9c75923e7912ee952bf348cab.tar.gz
nextcloud-server-55fcffd11a02c3c9c75923e7912ee952bf348cab.zip
Use IURLGenerator function to get value of `\OC::$WEBROOT` global
Signed-off-by: Jonas Meurer <jonas@freesources.org>
-rw-r--r--core/Controller/UnifiedSearchController.php10
-rw-r--r--lib/private/URLGenerator.php7
-rw-r--r--lib/public/IURLGenerator.php6
-rw-r--r--tests/lib/UrlGeneratorTest.php6
4 files changed, 27 insertions, 2 deletions
diff --git a/core/Controller/UnifiedSearchController.php b/core/Controller/UnifiedSearchController.php
index 3836c9a6d41..bfed6d606ae 100644
--- a/core/Controller/UnifiedSearchController.php
+++ b/core/Controller/UnifiedSearchController.php
@@ -33,6 +33,7 @@ use OCP\AppFramework\OCSController;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
+use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\Route\IRouter;
use OCP\Search\ISearchQuery;
@@ -49,15 +50,20 @@ class UnifiedSearchController extends OCSController {
/** @var IRouter */
private $router;
+ /** @var IURLGenerator */
+ private $urlGenerator;
+
public function __construct(IRequest $request,
IUserSession $userSession,
SearchComposer $composer,
- IRouter $router) {
+ IRouter $router,
+ IURLGenerator $urlGenerator) {
parent::__construct('core', $request);
$this->composer = $composer;
$this->userSession = $userSession;
$this->router = $router;
+ $this->urlGenerator = $urlGenerator;
}
/**
@@ -127,7 +133,7 @@ class UnifiedSearchController extends OCSController {
// Optionally strip webroot from URL. Required for route matching on setups
// with Nextcloud in a webserver subfolder (webroot).
- $webroot = \OC::$WEBROOT;
+ $webroot = $this->urlGenerator->getWebroot();
if ($webroot !== '' && substr($urlPath, 0, strlen($webroot)) === $webroot) {
$urlPath = substr($urlPath, strlen($webroot));
}
diff --git a/lib/private/URLGenerator.php b/lib/private/URLGenerator.php
index 34bb65cd0e6..f7fa6fa5632 100644
--- a/lib/private/URLGenerator.php
+++ b/lib/private/URLGenerator.php
@@ -276,4 +276,11 @@ class URLGenerator implements IURLGenerator {
}
return $this->baseUrl;
}
+
+ /**
+ * @return string webroot part of the base url
+ */
+ public function getWebroot(): string {
+ return \OC::$WEBROOT;
+ }
}
diff --git a/lib/public/IURLGenerator.php b/lib/public/IURLGenerator.php
index 486ca47d252..9f1a6447eb4 100644
--- a/lib/public/IURLGenerator.php
+++ b/lib/public/IURLGenerator.php
@@ -102,4 +102,10 @@ interface IURLGenerator {
* @since 13.0.0
*/
public function getBaseUrl(): string;
+
+ /**
+ * @return string webroot part of the base url
+ * @since 23.0.0
+ */
+ public function getWebroot(): string;
}
diff --git a/tests/lib/UrlGeneratorTest.php b/tests/lib/UrlGeneratorTest.php
index dd2eb2ddc63..761f4b42eea 100644
--- a/tests/lib/UrlGeneratorTest.php
+++ b/tests/lib/UrlGeneratorTest.php
@@ -179,6 +179,12 @@ class UrlGeneratorTest extends \Test\TestCase {
$this->assertEquals($expected, $actual);
}
+ public function testGetWebroot() {
+ \OC::$WEBROOT = '/nextcloud';
+ $actual = $this->urlGenerator->getWebroot();
+ $this->assertEquals(\OC::$WEBROOT, $actual);
+ }
+
/**
* @dataProvider provideOCSRoutes
*/