Skip to content

Commit 4eed1b6

Browse files
committed
fix: remove esc(strip_tags()) from RouteCollection default setters
1 parent 70c99eb commit 4eed1b6

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

system/Router/RouteCollection.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,22 +402,21 @@ public function getPlaceholders(): array
402402

403403
public function setDefaultNamespace(string $value): RouteCollectionInterface
404404
{
405-
$this->defaultNamespace = esc(strip_tags($value));
406-
$this->defaultNamespace = rtrim($this->defaultNamespace, '\\') . '\\';
405+
$this->defaultNamespace = rtrim($value, '\\') . '\\';
407406

408407
return $this;
409408
}
410409

411410
public function setDefaultController(string $value): RouteCollectionInterface
412411
{
413-
$this->defaultController = esc(strip_tags($value));
412+
$this->defaultController = $value;
414413

415414
return $this;
416415
}
417416

418417
public function setDefaultMethod(string $value): RouteCollectionInterface
419418
{
420-
$this->defaultMethod = esc(strip_tags($value));
419+
$this->defaultMethod = $value;
421420

422421
return $this;
423422
}

tests/system/Router/RouteCollectionTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,14 @@ public function testSetDefaultControllerStoresIt(): void
272272
$this->assertSame('godzilla', $routes->getDefaultController());
273273
}
274274

275+
public function testSetDefaultControllerPreservesSpecialCharacters(): void
276+
{
277+
$routes = $this->getCollector();
278+
$routes->setDefaultController('Foo&Bar');
279+
280+
$this->assertSame('Foo&Bar', $routes->getDefaultController());
281+
}
282+
275283
public function testSetDefaultMethodStoresIt(): void
276284
{
277285
$routes = $this->getCollector();
@@ -280,6 +288,22 @@ public function testSetDefaultMethodStoresIt(): void
280288
$this->assertSame('biggerBox', $routes->getDefaultMethod());
281289
}
282290

291+
public function testSetDefaultMethodPreservesSpecialCharacters(): void
292+
{
293+
$routes = $this->getCollector();
294+
$routes->setDefaultMethod('get&set');
295+
296+
$this->assertSame('get&set', $routes->getDefaultMethod());
297+
}
298+
299+
public function testSetDefaultNamespacePreservesSpecialCharacters(): void
300+
{
301+
$routes = $this->getCollector();
302+
$routes->setDefaultNamespace('App\Controllers&Services');
303+
304+
$this->assertSame('App\Controllers&Services\\', $routes->getDefaultNamespace());
305+
}
306+
283307
public function testTranslateURIDashesWorks(): void
284308
{
285309
$routes = $this->getCollector();

user_guide_src/source/changelogs/v4.7.5.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Bugs Fixed
3939
- **Helpers:** Fixed a bug where ``get_dir_file_info()`` returned incomplete entries for subdirectories and missing files instead of omitting them.
4040
- **Honeypot:** Fixed a bug where bot detection returned an HTTP 500 response instead of 403 (Forbidden).
4141
- **Logger:** Fixed a bug where interpolating a log message with array or non-stringable context values could raise PHP warnings or errors.
42+
- **Router:** Fixed a bug where ``RouteCollection::setDefaultNamespace()``, ``setDefaultController()``, and ``setDefaultMethod()`` incorrectly applied ``esc(strip_tags())``, which encoded HTML entities in PHP identifiers.
4243

4344
See the repo's
4445
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_

0 commit comments

Comments
 (0)