UnifiedSearchController: strip webroot from URL before finding a route

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>
This commit is contained in:
Jonas Meurer 2021-08-03 17:27:48 +02:00 committed by backportbot[bot]
parent 3c6dec3061
commit 7ddfd4dbc2

View 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'];