Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First attempt to check against core routes before loading all app routes #24295

Merged
merged 1 commit into from
Jun 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions lib/private/Route/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,32 +234,29 @@ public function create($name,
* @throws \Exception
* @return array
*/
public function findMatchingRoute(string $url): array {
if (substr($url, 0, 6) === '/apps/') {
public function findMatchingRoute(string $url, bool $loadAll = false): array {
if (strpos($url, '/apps/') === 0) {
// empty string / 'apps' / $app / rest of the route
[, , $app,] = explode('/', $url, 4);

$app = \OC_App::cleanAppId($app);
\OC::$REQUESTEDAPP = $app;
$this->loadRoutes($app);
} elseif (substr($url, 0, 13) === '/ocsapp/apps/') {
} elseif (strpos($url, '/ocsapp/apps/') === 0) {
// empty string / 'ocsapp' / 'apps' / $app / rest of the route
[, , , $app,] = explode('/', $url, 5);

$app = \OC_App::cleanAppId($app);
\OC::$REQUESTEDAPP = $app;
$this->loadRoutes($app);
} elseif (substr($url, 0, 10) === '/settings/') {
} elseif (strpos($url, '/settings/') === 0) {
$this->loadRoutes('settings');
} elseif (substr($url, 0, 6) === '/core/') {
\OC::$REQUESTEDAPP = $url;
if (!\OC::$server->getConfig()->getSystemValueBool('maintenance') && !Util::needUpgrade()) {
\OC_App::loadApps();
}
$this->loadRoutes('core');
} else {
$this->loadRoutes();
}
\OC::$REQUESTEDAPP = $url;
if (!\OC::$server->getConfig()->getSystemValueBool('maintenance') && !Util::needUpgrade()) {
\OC_App::loadApps();
}
$this->loadRoutes('core');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just loading the core routes here seems instead of all routes causes the guests app to be loaded too late so the AppConfigOverwrite is not yet registered when the DI is assembling the arguments for the autocomplete controller 🙈

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems this is due to https://github.com/nextcloud/guests/blob/eb7eb7c1b31e751bbbcc7671e5e1997b82297d45/appinfo/routes.php#L22-L26 where I'm not sure why the late setup would be needed here. A quick test for moving that to app.php seems to fix the issue

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how to proceed, then ? I don't have enough core knowledge to be able to evaluate whether your proposed change is safe to fix nextcloud/guests#654


$matcher = new UrlMatcher($this->root, $this->context);
try {
Expand All @@ -272,6 +269,11 @@ public function findMatchingRoute(string $url): array {
try {
$parameters = $matcher->match($url . '/');
} catch (ResourceNotFoundException $newException) {
// Attempt to fallback to load all routes if none of the above route patterns matches and the route is not in core
if (!$loadAll) {
$this->loadRoutes();
return $this->findMatchingRoute($url, true);
}
// If we still didn't match a route, we throw the original exception
throw $e;
}
Expand Down