Skip to content

Commit 500c837

Browse files
authored
Filter out invalid middleware values (#57436)
1 parent c11386e commit 500c837

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Illuminate/Routing/RouteRegistrar.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ public function attribute($key, $value)
121121
}
122122

123123
if ($key === 'middleware') {
124+
$value = array_filter(Arr::wrap($value));
125+
124126
foreach ($value as $index => $middleware) {
125127
$value[$index] = (string) $middleware;
126128
}

tests/Routing/RouteRegistrarTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,23 @@ public function __toString()
127127
$this->assertSame(['one', 'two'], $this->getRoute()->middleware());
128128
}
129129

130+
public function testMiddlewareAsNull()
131+
{
132+
$this->router->middleware(null)->get('users', function () {
133+
return 'all-users';
134+
});
135+
136+
$this->seeResponse('all-users', Request::create('users', 'GET'));
137+
$this->assertSame([], $this->getRoute()->middleware());
138+
139+
$this->router->get('users', function () {
140+
return 'all-users';
141+
})->middleware(null);
142+
143+
$this->seeResponse('all-users', Request::create('users', 'GET'));
144+
$this->assertSame([], $this->getRoute()->middleware());
145+
}
146+
130147
public function testWithoutMiddlewareRegistration()
131148
{
132149
$this->router->middleware(['one', 'two'])->get('users', function () {

0 commit comments

Comments
 (0)