Skip to content

fix: spark routes may show BadRequestException when a route has a regexp #8974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
Loading