From 9826222b106df50540a9baac435bca21f5758c8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20H=C3=B6gberg?= Date: Thu, 10 Mar 2022 12:58:07 +0100 Subject: [PATCH 1/2] Add failing test for passing null to Str::contains --- .../Testing/Console/RouteListCommandTest.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/Testing/Console/RouteListCommandTest.php b/tests/Testing/Console/RouteListCommandTest.php index db2df22b701a..ea6808e55fcd 100644 --- a/tests/Testing/Console/RouteListCommandTest.php +++ b/tests/Testing/Console/RouteListCommandTest.php @@ -5,6 +5,7 @@ use Illuminate\Contracts\Routing\Registrar; use Illuminate\Foundation\Auth\User; use Illuminate\Foundation\Console\RouteListCommand; +use Illuminate\Foundation\Testing\Concerns\InteractsWithDeprecationHandling; use Illuminate\Http\RedirectResponse; use Illuminate\Routing\Controller; use Illuminate\Support\Facades\Facade; @@ -12,6 +13,8 @@ class RouteListCommandTest extends TestCase { + use InteractsWithDeprecationHandling; + /** * @var \Illuminate\Contracts\Routing\Registrar */ @@ -92,6 +95,24 @@ public function testDisplayRoutesForCliInVerboseMode() ->expectsOutput(''); } + public function testRouteCanBeFilteredByName() + { + $this->withoutDeprecationHandling(); + + $this->router->get('/', function () { + // + }); + $this->router->get('/foo', function () { + // + })->name('foo.show'); + + $this->artisan(RouteListCommand::class, ['--name' => 'foo']) + ->assertSuccessful() + ->expectsOutput('') + ->expectsOutput(' GET|HEAD foo ...................................... foo.show') + ->expectsOutput(''); + } + protected function tearDown(): void { parent::tearDown(); From a22ada0e643a6de23f7e5f5a3304f8621830a85e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20H=C3=B6gberg?= Date: Thu, 10 Mar 2022 12:58:34 +0100 Subject: [PATCH 2/2] Fix issue by casting route name and domain to string since they can be null --- src/Illuminate/Foundation/Console/RouteListCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Foundation/Console/RouteListCommand.php b/src/Illuminate/Foundation/Console/RouteListCommand.php index 08f8b392ece9..782b827d3b1a 100644 --- a/src/Illuminate/Foundation/Console/RouteListCommand.php +++ b/src/Illuminate/Foundation/Console/RouteListCommand.php @@ -240,10 +240,10 @@ protected function isVendorRoute(Route $route) */ protected function filterRoute(array $route) { - if (($this->option('name') && ! Str::contains($route['name'], $this->option('name'))) || + if (($this->option('name') && ! Str::contains((string) $route['name'], $this->option('name'))) || ($this->option('path') && ! Str::contains($route['uri'], $this->option('path'))) || ($this->option('method') && ! Str::contains($route['method'], strtoupper($this->option('method')))) || - ($this->option('domain') && ! Str::contains($route['domain'], $this->option('domain'))) || + ($this->option('domain') && ! Str::contains((string) $route['domain'], $this->option('domain'))) || ($this->option('except-vendor') && $route['vendor'])) { return; }