diff --git a/system/Router/AutoRouterImproved.php b/system/Router/AutoRouterImproved.php index 57d5ca0ad610..09a796ae0f3c 100644 --- a/system/Router/AutoRouterImproved.php +++ b/system/Router/AutoRouterImproved.php @@ -162,7 +162,7 @@ private function searchFirstController(): bool $segment = array_shift($segments); $controllerPos++; - $class = $this->translateURIDashes($segment); + $class = $this->translateURI($segment); // as soon as we encounter any segment that is not PSR-4 compliant, stop searching if (! $this->isValidSegment($class)) { @@ -209,7 +209,7 @@ private function searchLastDefaultController(): bool } $namespaces = array_map( - fn ($segment) => $this->translateURIDashes($segment), + fn ($segment) => $this->translateURI($segment), $segments ); @@ -307,7 +307,7 @@ public function getRoute(string $uri, string $httpVerb): array $method = ''; if ($methodParam !== null) { - $method = $httpVerb . $this->translateURIDashes($methodParam); + $method = $httpVerb . $this->translateURI($methodParam); $this->checkUriForMethod($method); } @@ -544,7 +544,10 @@ private function isValidSegment(string $segment): bool return (bool) preg_match('/^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$/', $segment); } - private function translateURIDashes(string $segment): string + /** + * Translates URI segment to CamelCase or replaces `-` with `_`. + */ + private function translateURI(string $segment): string { if ($this->translateUriToCamelCase) { if (strtolower($segment) !== $segment) {