Skip to content

Commit cd46db1

Browse files
authored
Merge pull request #8974 from kenjis/fix-spark-routes-BadRequestException
fix: `spark routes` may show BadRequestException when a route has a regexp
2 parents c8b8995 + 4ad4bd3 commit cd46db1

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

system/Commands/Utilities/Routes/FilterFinder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use CodeIgniter\Exceptions\PageNotFoundException;
1717
use CodeIgniter\Filters\Filters;
18+
use CodeIgniter\HTTP\Exceptions\BadRequestException;
1819
use CodeIgniter\HTTP\Exceptions\RedirectException;
1920
use CodeIgniter\Router\Router;
2021
use Config\Feature;
@@ -72,7 +73,7 @@ public function find(string $uri): array
7273
'before' => [],
7374
'after' => [],
7475
];
75-
} catch (PageNotFoundException) {
76+
} catch (BadRequestException|PageNotFoundException) {
7677
return [
7778
'before' => ['<unknown>'],
7879
'after' => ['<unknown>'],

system/Config/BaseService.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ public static function serviceExists(string $name): ?string
346346
* Reset shared instances and mocks for testing.
347347
*
348348
* @return void
349+
*
350+
* @testTag only available to test code
349351
*/
350352
public static function reset(bool $initAutoloader = true)
351353
{
@@ -362,6 +364,8 @@ public static function reset(bool $initAutoloader = true)
362364
* Resets any mock and shared instances for a single service.
363365
*
364366
* @return void
367+
*
368+
* @testTag only available to test code
365369
*/
366370
public static function resetSingle(string $name)
367371
{
@@ -375,6 +379,8 @@ public static function resetSingle(string $name)
375379
* @param object $mock
376380
*
377381
* @return void
382+
*
383+
* @testTag only available to test code
378384
*/
379385
public static function injectMock(string $name, $mock)
380386
{

system/Router/Router.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ public function __construct(RouteCollectionInterface $routes, ?Request $request
187187
*
188188
* @return (Closure(mixed...): (ResponseInterface|string|void))|string Controller classname or Closure
189189
*
190+
* @throws BadRequestException
190191
* @throws PageNotFoundException
191192
* @throws RedirectException
192193
*/

tests/system/Commands/RoutesTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,18 @@ public function testRoutesCommandRouteLegacy(): void
240240
EOL;
241241
$this->assertStringContainsString($expected, $this->getBuffer());
242242
}
243+
244+
public function testRoutesCommandRouteWithRegexp(): void
245+
{
246+
$routes = Services::routes();
247+
$routes->resetRoutes();
248+
$routes->options('picker/(.+)', 'Options::index');
249+
250+
command('routes');
251+
252+
$expected = <<<'EOL'
253+
| OPTIONS | picker/(.+) | » | \App\Controllers\Options::index | <unknown> | <unknown> |
254+
EOL;
255+
$this->assertStringContainsString($expected, $this->getBuffer());
256+
}
243257
}

0 commit comments

Comments
 (0)