Repository: codeigniter4/CodeIgniter4 (PHP)

Issue:
Bug: Routing groups and in-group routes use filters that are only effective within the group.
### PHP Version

8.1

### CodeIgniter4 Version

4.5.3

### CodeIgniter4 Installation Method

Composer (using `codeigniter4/appstarter`)

### Which operating systems have you tested for this bug?

Windows

### Which server did you use?

apache

### Database

MySQL 5.7

### What happened?

When I use a route group filter, and then use the filter on the routes within the route group, it only takes effect on the filters within the group.

### Steps to Reproduce

```php
//Routers

$routes->group('',['filter'=>['auth']],function($routes){
    $routes->get('getuserinfo','Mmeber::getUserInfo',['filter'=>['throttle']]);
});
```

Use filter:check output:
```
+--------+--------------+------------------------------------------+----------------------------------------+
| Method | Route        | Before Filters                           | After Filters                          |
+--------+--------------+------------------------------------------+----------------------------------------+
| GET    | /getuserinfo | forcehttps pagecache csrf token throttle | throttle pagecache performance toolbar |
+--------+--------------+------------------------------------------+----------------------------------------+
```
The csrf,token is globals filter,I think the filter execution order should be from the route group to the route within the group.For example:csrf->token->auth->throttle.But it does not include the route group filter.

### Expected Output

I want the filter to include the route group filter.

The above content is translated by Google, so there may be some errors, but I hope this error can be fixed.

### Anything else?

_No response_


Discussion:
Thank you for reporting!
Check #9064




Patch:
diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php
index 322987dc791b..8fba39dc03be 100644
--- a/system/Router/RouteCollection.php
+++ b/system/Router/RouteCollection.php
@@ -1456,6 +1456,12 @@ protected function create(string $verb, string $from, $to, ?array $options = nul
             $to = $this->processArrayCallableSyntax($from, $to);
         }
 
+        // Merge group filters.
+        if (isset($options['filter'])) {
+            $currentFilter     = (array) ($this->currentOptions['filter'] ?? []);
+            $options['filter'] = array_merge($currentFilter, (array) $options['filter']);
+        }
+
         $options = array_merge($this->currentOptions ?? [], $options ?? []);
 
         // Route priority detect
diff --git a/user_guide_src/source/changelogs/v4.5.4.rst b/user_guide_src/source/changelogs/v4.5.4.rst
index 51a9fd74f407..d09413124ee0 100644
--- a/user_guide_src/source/changelogs/v4.5.4.rst
+++ b/user_guide_src/source/changelogs/v4.5.4.rst
@@ -30,6 +30,8 @@ Deprecations
 Bugs Fixed
 **********
 
+- **Routing:** Fixed a bug that filters passed to ``$routes->group()`` were not
+  merged into filters passed to the inner routes.
 - **CURLRequest:** Fixed a bug preventing the use of strings for ``version`` in the config array
   when making requests.
 
diff --git a/user_guide_src/source/incoming/routing.rst b/user_guide_src/source/incoming/routing.rst
index b822d4cce17e..90c99ad73b61 100644
--- a/user_guide_src/source/incoming/routing.rst
+++ b/user_guide_src/source/incoming/routing.rst
@@ -564,6 +564,9 @@ run the filter before or after the controller. This is especially handy during a
 
 The value for the filter must match one of the aliases defined within **app/Config/Filters.php**.
 
+.. note:: Prior to v4.5.4, due to a bug, filters passed to the ``group()`` were
+    not merged into the filters passed to the inner routes.
+
 Setting Other Options
 =====================
 


Test patch:
diff --git a/tests/system/Router/RouteCollectionTest.php b/tests/system/Router/RouteCollectionTest.php
index 89959cd5f33e..5c06154a5d31 100644
--- a/tests/system/Router/RouteCollectionTest.php
+++ b/tests/system/Router/RouteCollectionTest.php
@@ -440,6 +440,22 @@ static function ($routes): void {
         $this->assertSame($expected, $routes->getRoutesOptions());
     }
 
+    public function testGroupFilterAndRouteFilter(): void
+    {
+        $routes = $this->getCollector();
+
+        $routes->group('admin', ['filter' => ['csrf']], static function ($routes): void {
+            $routes->get('profile', 'Admin\Profile::index', ['filter' => ['honeypot']]);
+        });
+
+        $expected = [
+            'admin/profile' => [
+                'filter' => ['csrf', 'honeypot'],
+            ],
+        ];
+        $this->assertSame($expected, $routes->getRoutesOptions());
+    }
+
     public function testGroupingWorksWithEmptyStringPrefix(): void
     {
         $routes = $this->getCollector();