diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2023-11-20 17:00:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-20 17:00:43 +0100 |
commit | e5b996722a3f850bec68490d467e8c565f3a3341 (patch) | |
tree | 571e091ed0892dbeadd83795c91f4d5bb62445fb /lib | |
parent | 0da05fc73b720702b76d8838228f3ce648793482 (diff) | |
parent | 572ea18ac7a706f6d7485e8e80e85315cf809220 (diff) | |
download | nextcloud-server-e5b996722a3f850bec68490d467e8c565f3a3341.tar.gz nextcloud-server-e5b996722a3f850bec68490d467e8c565f3a3341.zip |
Merge pull request #41616 from nextcloud/bugfix/noid/fix-ocs-absolute-URLs-with-ignore-front-controller
fix: Fix linkToOCSRouteAbsolute() without index.php and with subfolder
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/URLGenerator.php | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/private/URLGenerator.php b/lib/private/URLGenerator.php index 57bafc3e18d..4e9a23b3eae 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); } |