Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 5 additions & 6 deletions system/Router/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
45 changes: 44 additions & 1 deletion tests/system/Router/RouteCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -732,7 +756,7 @@ public function testResourcesWithCustomController(): void
service('request')->setMethod(Method::GET);
$routes = $this->getCollector();

$routes->resource('photos', ['controller' => '<script>gallery']);
$routes->resource('photos', ['controller' => 'gallery']);

$expected = [
'photos' => '\Gallery::index',
Expand All @@ -744,6 +768,25 @@ public function testResourcesWithCustomController(): void
$this->assertSame($expected, $routes->getRoutes());
}

public function testPresenterWithCustomController(): void
{
service('request')->setMethod(Method::GET);
$routes = $this->getCollector();

$routes->presenter('photos', ['controller' => 'gallery']);

$expected = [
'photos' => '\Gallery::index',
'photos/show/(.*)' => '\Gallery::show/$1',
'photos/new' => '\Gallery::new',
'photos/edit/(.*)' => '\Gallery::edit/$1',
'photos/remove/(.*)' => '\Gallery::remove/$1',
'photos/(.*)' => '\Gallery::show/$1',
];

$this->assertSame($expected, $routes->getRoutes());
}

public function testResourcesWithCustomPlaceholder(): void
{
service('request')->setMethod(Method::GET);
Expand Down
1 change: 1 addition & 0 deletions user_guide_src/source/changelogs/v4.8.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ Changes
*******

- **Config:** Added the ``md`` key for ``Config\Mimes::$mimes`` for Markdown files.
- **Router:** Removed inappropriate ``esc(strip_tags())`` input transformations on controller and method identifiers in ``RouteCollection``.

************
Deprecations
Expand Down