From 5d12f1231975ab7249ad554f0d0a3c8d2eb67b13 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 20 Nov 2023 11:18:47 +0100 Subject: fix: Fix linkToOCSRouteAbsolute() without index.php and subfolder Signed-off-by: Joas Schilling --- lib/private/URLGenerator.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/private/URLGenerator.php b/lib/private/URLGenerator.php index 2410b8a9147..5745cde274e 100644 --- a/lib/private/URLGenerator.php +++ b/lib/private/URLGenerator.php @@ -116,16 +116,25 @@ class URLGenerator implements IURLGenerator { } public function linkToOCSRouteAbsolute(string $routeName, array $arguments = []): string { + // Returns `/subfolder/index.php/ocsapp/…` with `'htaccess.IgnoreFrontController' => false` in config.php + // And `/subfolder/ocsapp/…` with `'htaccess.IgnoreFrontController' => true` in config.php $route = $this->router->generate('ocs.'.$routeName, $arguments, false); - $indexPhpPos = strpos($route, '/index.php/'); - if ($indexPhpPos !== false) { - $route = substr($route, $indexPhpPos + 10); + // Cut off `/subfolder` + if (\OC::$WEBROOT !== '' && str_starts_with($route, \OC::$WEBROOT)) { + $route = substr($route, \strlen(\OC::$WEBROOT)); } + if (str_starts_with($route, '/index.php/')) { + $route = substr($route, 10); + } + + // Remove `ocsapp/` bit $route = substr($route, 7); + // Prefix with ocs/v2.php endpoint $route = '/ocs/v2.php' . $route; + // Turn into an absolute URL return $this->getAbsoluteURL($route); } -- cgit v1.2.3