diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 9b68a3738785..8428ca7a303a 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -404,22 +404,21 @@ public function getPlaceholders(): array public function setDefaultNamespace(string $value): RouteCollectionInterface { - $this->defaultNamespace = esc(strip_tags($value)); - $this->defaultNamespace = rtrim($this->defaultNamespace, '\\') . '\\'; + $this->defaultNamespace = rtrim($value, '\\') . '\\'; return $this; } public function setDefaultController(string $value): RouteCollectionInterface { - $this->defaultController = esc(strip_tags($value)); + $this->defaultController = $value; return $this; } public function setDefaultMethod(string $value): RouteCollectionInterface { - $this->defaultMethod = esc(strip_tags($value)); + $this->defaultMethod = $value; return $this; } @@ -754,7 +753,7 @@ public function resource(string $name, ?array $options = null): RouteCollectionI // If a new controller is specified, then we replace the // $name value with the name of the new controller. if (isset($options['controller'])) { - $newName = ucfirst(esc(strip_tags($options['controller']))); + $newName = ucfirst($options['controller']); } // In order to allow customization of allowed id values @@ -848,7 +847,7 @@ public function presenter(string $name, ?array $options = null): RouteCollection // If a new controller is specified, then we replace the // $name value with the name of the new controller. if (isset($options['controller'])) { - $newName = ucfirst(esc(strip_tags($options['controller']))); + $newName = ucfirst($options['controller']); } // In order to allow customization of allowed id values diff --git a/tests/system/Router/RouteCollectionTest.php b/tests/system/Router/RouteCollectionTest.php index 24ef9001f001..03cf7d2b48e6 100644 --- a/tests/system/Router/RouteCollectionTest.php +++ b/tests/system/Router/RouteCollectionTest.php @@ -272,6 +272,14 @@ public function testSetDefaultControllerStoresIt(): void $this->assertSame('godzilla', $routes->getDefaultController()); } + public function testSetDefaultControllerPreservesSpecialCharacters(): void + { + $routes = $this->getCollector(); + $routes->setDefaultController('Foo&Bar'); + + $this->assertSame('Foo&Bar', $routes->getDefaultController()); + } + public function testSetDefaultMethodStoresIt(): void { $routes = $this->getCollector(); @@ -280,6 +288,22 @@ public function testSetDefaultMethodStoresIt(): void $this->assertSame('biggerBox', $routes->getDefaultMethod()); } + public function testSetDefaultMethodPreservesSpecialCharacters(): void + { + $routes = $this->getCollector(); + $routes->setDefaultMethod('get&set'); + + $this->assertSame('get&set', $routes->getDefaultMethod()); + } + + public function testSetDefaultNamespacePreservesSpecialCharacters(): void + { + $routes = $this->getCollector(); + $routes->setDefaultNamespace('App\Controllers&Services'); + + $this->assertSame('App\Controllers&Services\\', $routes->getDefaultNamespace()); + } + public function testTranslateURIDashesWorks(): void { $routes = $this->getCollector(); @@ -732,7 +756,7 @@ public function testResourcesWithCustomController(): void service('request')->setMethod(Method::GET); $routes = $this->getCollector(); - $routes->resource('photos', ['controller' => '