Skip to content

Commit 6dab8f8

Browse files
committed
Filters match case-insensitively. Fixes #1664
1 parent 416da00 commit 6dab8f8

2 files changed

Lines changed: 48 additions & 6 deletions

File tree

system/Filters/Filters.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function setResponse(ResponseInterface $response)
119119
*/
120120
public function run(string $uri, $position = 'before')
121121
{
122-
$this->initialize($uri);
122+
$this->initialize(strtolower($uri));
123123

124124
foreach ($this->filters[$position] as $alias => $rules)
125125
{
@@ -350,7 +350,7 @@ protected function processGlobals(string $uri = null)
350350
foreach ($rules as $path)
351351
{
352352
// Prep it for regex
353-
$path = str_replace('/*', '*', $path);
353+
$path = strtolower(str_replace('/*', '*', $path));
354354
$path = trim(str_replace('*', '.+', $path), '/ ');
355355

356356
// Path doesn't match the URI? continue on...
@@ -388,7 +388,7 @@ protected function processGlobals(string $uri = null)
388388
foreach ($rules as $path)
389389
{
390390
// Prep it for regex
391-
$path = str_replace('/*', '*', $path);
391+
$path = strtolower(str_replace('/*', '*', $path));
392392
$path = trim(str_replace('*', '.+', $path), '/ ');
393393

394394
// Path doesn't match the URI? continue on...
@@ -434,7 +434,7 @@ protected function processFilters(string $uri = null)
434434
return;
435435
}
436436

437-
$uri = trim($uri, '/ ');
437+
$uri = strtolower(trim($uri, '/ '));
438438

439439
$matches = [];
440440

@@ -446,7 +446,7 @@ protected function processFilters(string $uri = null)
446446
foreach ($settings['before'] as $path)
447447
{
448448
// Prep it for regex
449-
$path = str_replace('/*', '*', $path);
449+
$path = strtolower(str_replace('/*', '*', $path));
450450
$path = trim(str_replace('*', '.+', $path), '/ ');
451451

452452
if (preg_match('#' . $path . '#', $uri) !== 1)
@@ -467,7 +467,7 @@ protected function processFilters(string $uri = null)
467467
foreach ($settings['after'] as $path)
468468
{
469469
// Prep it for regex
470-
$path = str_replace('/*', '*', $path);
470+
$path = strtolower(str_replace('/*', '*', $path));
471471
$path = trim(str_replace('*', '.+', $path), '/ ');
472472

473473
if (preg_match('#' . $path . '#', $uri) !== 1)

tests/system/Filters/FiltersTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,4 +637,46 @@ public function testEnableNonFilter()
637637
$filters->enableFilter('goggle', 'before');
638638
}
639639

640+
/**
641+
* @see https://github.com/codeigniter4/CodeIgniter4/issues/1664
642+
*/
643+
public function testMatchesURICaseInsensitively()
644+
{
645+
$_SERVER['REQUEST_METHOD'] = 'GET';
646+
647+
$config = [
648+
'globals' => [
649+
'before' => [
650+
'foo' => ['except' => 'Admin/*'],
651+
'bar'
652+
],
653+
'after' => [
654+
'foo' => ['except' => 'Admin/*'],
655+
'baz'
656+
],
657+
],
658+
'filters' => [
659+
'frak' => [
660+
'before' => ['Admin/*'],
661+
'after' => ['Admin/*'],
662+
],
663+
],
664+
];
665+
$filters = new Filters((object) $config, $this->request, $this->response);
666+
$uri = 'admin/foo/bar';
667+
668+
$expected = [
669+
'before' => [
670+
'bar',
671+
'frak',
672+
],
673+
'after' => [
674+
'baz',
675+
'frak',
676+
],
677+
];
678+
679+
$this->assertEquals($expected, $filters->initialize($uri)->getFilters());
680+
}
681+
640682
}

0 commit comments

Comments
 (0)