Skip to content

Commit

Permalink
[8.x] fix Request offsetExists without routeResolver (#42754)
Browse files Browse the repository at this point in the history
* fix Request offsetExists without routeResolver

* simplify test

* formatting

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
danesteve and taylorotwell authored Jun 10, 2022
1 parent 76faca7 commit cd6e76f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Illuminate/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,10 @@ public function toArray()
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
$route = $this->route();

return Arr::has(
$this->all() + $this->route()->parameters(),
$this->all() + ($route ? $route->parameters() : []),
$offset
);
}
Expand Down
11 changes: 11 additions & 0 deletions tests/Http/HttpRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,17 @@ public function testArrayAccess()
$this->assertSame('foo', $request['id']);
}

public function testArrayAccessWithoutRouteResolver()
{
$request = Request::create('/', 'GET', ['name' => 'Taylor']);

$this->assertFalse(isset($request['non-existent']));
$this->assertNull($request['non-existent']);

$this->assertTrue(isset($request['name']));
$this->assertSame('Taylor', $request['name']);
}

public function testAllMethod()
{
$request = Request::create('/', 'GET', ['name' => 'Taylor', 'age' => null]);
Expand Down

0 comments on commit cd6e76f

Please sign in to comment.