3434use OCP \AppFramework \Http ;
3535use OCP \AppFramework \Http \DataResponse ;
3636use OCP \IRequest ;
37+ use OCP \IURLGenerator ;
3738use OCP \IUserSession ;
3839use OCP \Route \IRouter ;
3940use OCP \Search \ISearchQuery ;
@@ -50,15 +51,20 @@ class UnifiedSearchController extends OCSController {
5051 /** @var IRouter */
5152 private $ router ;
5253
54+ /** @var IURLGenerator */
55+ private $ urlGenerator ;
56+
5357 public function __construct (IRequest $ request ,
5458 IUserSession $ userSession ,
5559 SearchComposer $ composer ,
56- IRouter $ router ) {
60+ IRouter $ router ,
61+ IURLGenerator $ urlGenerator ) {
5762 parent ::__construct ('core ' , $ request );
5863
5964 $ this ->composer = $ composer ;
6065 $ this ->userSession = $ userSession ;
6166 $ this ->router = $ router ;
67+ $ this ->urlGenerator = $ urlGenerator ;
6268 }
6369
6470 /**
@@ -124,9 +130,17 @@ protected function getRouteInformation(string $url): array {
124130
125131 if ($ url !== '' ) {
126132 $ urlParts = parse_url ($ url );
133+ $ urlPath = $ urlParts ['path ' ];
134+
135+ // Optionally strip webroot from URL. Required for route matching on setups
136+ // with Nextcloud in a webserver subfolder (webroot).
137+ $ webroot = $ this ->urlGenerator ->getWebroot ();
138+ if ($ webroot !== '' && substr ($ urlPath , 0 , strlen ($ webroot )) === $ webroot ) {
139+ $ urlPath = substr ($ urlPath , strlen ($ webroot ));
140+ }
127141
128142 try {
129- $ parameters = $ this ->router ->findMatchingRoute ($ urlParts [ ' path ' ] );
143+ $ parameters = $ this ->router ->findMatchingRoute ($ urlPath );
130144
131145 // contacts.PageController.index => contacts.Page.index
132146 $ route = $ parameters ['caller ' ];
0 commit comments