Skip to content

Commit

Permalink
Merge pull request #8974 from kenjis/fix-spark-routes-BadRequestExcep…
Browse files Browse the repository at this point in the history
…tion

fix: `spark routes` may show BadRequestException when a route has a regexp
  • Loading branch information
kenjis committed Jun 19, 2024
2 parents c8b8995 + 4ad4bd3 commit cd46db1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion system/Commands/Utilities/Routes/FilterFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\Filters\Filters;
use CodeIgniter\HTTP\Exceptions\BadRequestException;
use CodeIgniter\HTTP\Exceptions\RedirectException;
use CodeIgniter\Router\Router;
use Config\Feature;
Expand Down Expand Up @@ -72,7 +73,7 @@ public function find(string $uri): array
'before' => [],
'after' => [],
];
} catch (PageNotFoundException) {
} catch (BadRequestException|PageNotFoundException) {
return [
'before' => ['<unknown>'],
'after' => ['<unknown>'],
Expand Down
6 changes: 6 additions & 0 deletions system/Config/BaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ public static function serviceExists(string $name): ?string
* Reset shared instances and mocks for testing.
*
* @return void
*
* @testTag only available to test code
*/
public static function reset(bool $initAutoloader = true)
{
Expand All @@ -362,6 +364,8 @@ public static function reset(bool $initAutoloader = true)
* Resets any mock and shared instances for a single service.
*
* @return void
*
* @testTag only available to test code
*/
public static function resetSingle(string $name)
{
Expand All @@ -375,6 +379,8 @@ public static function resetSingle(string $name)
* @param object $mock
*
* @return void
*
* @testTag only available to test code
*/
public static function injectMock(string $name, $mock)
{
Expand Down
1 change: 1 addition & 0 deletions system/Router/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public function __construct(RouteCollectionInterface $routes, ?Request $request
*
* @return (Closure(mixed...): (ResponseInterface|string|void))|string Controller classname or Closure
*
* @throws BadRequestException
* @throws PageNotFoundException
* @throws RedirectException
*/
Expand Down
14 changes: 14 additions & 0 deletions tests/system/Commands/RoutesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,18 @@ public function testRoutesCommandRouteLegacy(): void
EOL;
$this->assertStringContainsString($expected, $this->getBuffer());
}

public function testRoutesCommandRouteWithRegexp(): void
{
$routes = Services::routes();
$routes->resetRoutes();
$routes->options('picker/(.+)', 'Options::index');

command('routes');

$expected = <<<'EOL'
| OPTIONS | picker/(.+) | » | \App\Controllers\Options::index | <unknown> | <unknown> |
EOL;
$this->assertStringContainsString($expected, $this->getBuffer());
}
}

0 comments on commit cd46db1

Please sign in to comment.