Skip to content

Commit

Permalink
fix(Routing): Only use lowercase names for registering and matching r…
Browse files Browse the repository at this point in the history
…outes

Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
provokateurin committed Feb 21, 2024
1 parent ce91b2d commit 66e7056
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
8 changes: 7 additions & 1 deletion lib/private/AppFramework/Routing/RouteConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,13 @@ protected function processRoute(array $route, string $routeNamePrefix = ''): voi
$controllerName = $this->buildControllerName($controller);
$actionName = $this->buildActionName($action);

$routeName = $routeNamePrefix . $this->appName . '.' . $controller . '.' . $action . $postfix;
/*
* The route name has to be lowercase, for symfony to match it correctly.
* This is required because smyfony allows mixed casing for controller names in the routes.
* To avoid breaking all the existing route names, registering and matching will only use the lowercase names.
* This is also safe on the PHP side because class and method names collide regardless of the casing.
*/
$routeName = strtolower($routeNamePrefix . $this->appName . '.' . $controller . '.' . $action . $postfix);

$router = $this->router->create($routeName, $url)
->method($verb);
Expand Down
8 changes: 7 additions & 1 deletion lib/private/AppFramework/Routing/RouteParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@ private function processRoute(array $route, string $appName, string $routeNamePr
$controllerName = $this->buildControllerName($controller);
$actionName = $this->buildActionName($action);

$routeName = $routeNamePrefix . $appName . '.' . $controller . '.' . $action . $postfix;
/*
* The route name has to be lowercase, for symfony to match it correctly.
* This is required because smyfony allows mixed casing for controller names in the routes.
* To avoid breaking all the existing route names, registering and matching will only use the lowercase names.
* This is also safe on the PHP side because class and method names collide regardless of the casing.
*/
$routeName = strtolower($routeNamePrefix . $appName . '.' . $controller . '.' . $action . $postfix);

$routeObject = new Route($url);
$routeObject->method($verb);
Expand Down
37 changes: 22 additions & 15 deletions lib/private/Route/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,13 @@ public function generate($name,
if ($absolute === false) {
$referenceType = UrlGenerator::ABSOLUTE_PATH;
}
/*
* The route name has to be lowercase, for symfony to match it correctly.
* This is required because smyfony allows mixed casing for controller names in the routes.
* To avoid breaking all the existing route names, registering and matching will only use the lowercase names.
* This is also safe on the PHP side because class and method names collide regardless of the casing.
*/
$name = strtolower($name);
$name = $this->fixLegacyRootName($name);
if (str_contains($name, '.')) {
[$appName, $other] = explode('.', $name, 3);
Expand All @@ -385,29 +392,29 @@ public function generate($name,
}

protected function fixLegacyRootName(string $routeName): string {
if ($routeName === 'files.viewcontroller.showFile') {
return 'files.View.showFile';
if ($routeName === 'files.viewcontroller.showfile') {
return 'files.view.showfile';
}
if ($routeName === 'files_sharing.sharecontroller.showShare') {
return 'files_sharing.Share.showShare';
if ($routeName === 'files_sharing.sharecontroller.showshare') {
return 'files_sharing.share.showshare';
}
if ($routeName === 'files_sharing.sharecontroller.showAuthenticate') {
return 'files_sharing.Share.showAuthenticate';
if ($routeName === 'files_sharing.sharecontroller.showauthenticate') {
return 'files_sharing.share.showauthenticate';
}
if ($routeName === 'files_sharing.sharecontroller.authenticate') {
return 'files_sharing.Share.authenticate';
return 'files_sharing.share.authenticate';
}
if ($routeName === 'files_sharing.sharecontroller.downloadShare') {
return 'files_sharing.Share.downloadShare';
if ($routeName === 'files_sharing.sharecontroller.downloadshare') {
return 'files_sharing.share.downloadshare';
}
if ($routeName === 'files_sharing.publicpreview.directLink') {
return 'files_sharing.PublicPreview.directLink';
if ($routeName === 'files_sharing.publicpreview.directlink') {
return 'files_sharing.publicpreview.directlink';
}
if ($routeName === 'cloud_federation_api.requesthandlercontroller.addShare') {
return 'cloud_federation_api.RequestHandler.addShare';
if ($routeName === 'cloud_federation_api.requesthandlercontroller.addshare') {
return 'cloud_federation_api.requesthandler.addshare';
}
if ($routeName === 'cloud_federation_api.requesthandlercontroller.receiveNotification') {
return 'cloud_federation_api.RequestHandler.receiveNotification';
if ($routeName === 'cloud_federation_api.requesthandlercontroller.receivenotification') {
return 'cloud_federation_api.requesthandler.receivenotification';
}
return $routeName;
}
Expand Down

0 comments on commit 66e7056

Please sign in to comment.