]> source.dussan.org Git - nextcloud-server.git/commitdiff
UnifiedSearchController: strip webroot from URL before finding a route
authorJonas Meurer <jonas@freesources.org>
Tue, 3 Aug 2021 15:27:48 +0000 (17:27 +0200)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Mon, 16 Aug 2021 13:12:45 +0000 (13:12 +0000)
This should fix route matching in UnifiedSearchController on setups with
Nextcloud in a subfolder (webroot).

Fixes: #24144
Signed-off-by: Jonas Meurer <jonas@freesources.org>
core/Controller/UnifiedSearchController.php

index c2949ce6095814cecde70edeb001fcf5561f5c9e..2930e4840cecb65cac62e659c4552821507d33fa 100644 (file)
@@ -124,9 +124,17 @@ class UnifiedSearchController extends OCSController {
 
                if ($url !== '') {
                        $urlParts = parse_url($url);
+                       $urlPath = $urlParts['path'];
+
+                       // Optionally strip webroot from URL. Required for route matching on setups
+                       // with Nextcloud in a webserver subfolder (webroot).
+                       $webroot = \OC::$WEBROOT;
+                       if ($webroot !== '' && substr($urlPath, 0, strlen($webroot)) === $webroot) {
+                               $urlPath = substr($urlPath, strlen($webroot));
+                       }
 
                        try {
-                               $parameters = $this->router->findMatchingRoute($urlParts['path']);
+                               $parameters = $this->router->findMatchingRoute($urlPath);
 
                                // contacts.PageController.index => contacts.Page.index
                                $route = $parameters['caller'];