From ac963a0dc8bc0e06591ee704cf279f2bff3d66ce Mon Sep 17 00:00:00 2001 From: Lynn Lin Date: Wed, 2 May 2018 22:49:13 +0800 Subject: [PATCH] [5.5] Fix unsetting http query parameters when fetching request by HEAD (#24076) * fix request method to use $_GET variables when HEAD * fix coding style of http request --- src/Illuminate/Http/Request.php | 16 +++++++++++----- tests/Http/HttpRequestTest.php | 7 +++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Http/Request.php b/src/Illuminate/Http/Request.php index 6916063e3e73..aa315f91a1ed 100644 --- a/src/Illuminate/Http/Request.php +++ b/src/Illuminate/Http/Request.php @@ -340,7 +340,7 @@ protected function getInputSource() return $this->json(); } - return $this->getRealMethod() == 'GET' ? $this->query : $this->request; + return in_array($this->getRealMethod(), ['GET', 'HEAD']) ? $this->query : $this->request; } /** @@ -358,8 +358,12 @@ public static function createFromBase(SymfonyRequest $request) $content = $request->content; $request = (new static)->duplicate( - $request->query->all(), $request->request->all(), $request->attributes->all(), - $request->cookies->all(), $request->files->all(), $request->server->all() + $request->query->all(), + $request->request->all(), + $request->attributes->all(), + $request->cookies->all(), + $request->files->all(), + $request->server->all() ); $request->content = $content; @@ -472,7 +476,8 @@ public function fingerprint() } return sha1(implode('|', array_merge( - $route->methods(), [$route->getDomain(), $route->uri(), $this->ip()] + $route->methods(), + [$route->getDomain(), $route->uri(), $this->ip()] ))); } @@ -558,7 +563,8 @@ public function toArray() public function offsetExists($offset) { return array_key_exists( - $offset, $this->all() + $this->route()->parameters() + $offset, + $this->all() + $this->route()->parameters() ); } diff --git a/tests/Http/HttpRequestTest.php b/tests/Http/HttpRequestTest.php index 540d7878a7df..455a2d6656c5 100644 --- a/tests/Http/HttpRequestTest.php +++ b/tests/Http/HttpRequestTest.php @@ -453,6 +453,13 @@ public function testReplaceMethod() $this->assertEquals('Dayle', $request->input('buddy')); } + public function testOffsetUnsetMethod() + { + $request = Request::create('/', 'HEAD', ['name' => 'Taylor']); + $request->offsetUnset('name'); + $this->assertNull($request->input('name')); + } + public function testHeaderMethod() { $request = Request::create('/', 'GET', [], [], [], ['HTTP_DO_THIS' => 'foo']);