Skip to content

Commit 68ce705

Browse files
Phobetornicolas-grekas
authored andcommitted
[HttpFoundation] fixed using _method parameter with invalid type
1 parent ab52696 commit 68ce705

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Request.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,10 @@ public function getMethod()
12761276
if ($method = $this->headers->get('X-HTTP-METHOD-OVERRIDE')) {
12771277
$this->method = strtoupper($method);
12781278
} elseif (self::$httpMethodParameterOverride) {
1279-
$this->method = strtoupper($this->request->get('_method', $this->query->get('_method', 'POST')));
1279+
$method = $this->request->get('_method', $this->query->get('_method', 'POST'));
1280+
if (\is_string($method)) {
1281+
$this->method = strtoupper($method);
1282+
}
12801283
}
12811284
}
12821285
}

Tests/RequestTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,11 @@ public function testGetSetMethod()
816816
$request->setMethod('POST');
817817
$request->headers->set('X-HTTP-METHOD-OVERRIDE', 'delete');
818818
$this->assertEquals('DELETE', $request->getMethod(), '->getMethod() returns the method from X-HTTP-Method-Override if defined and POST');
819+
820+
$request = new Request();
821+
$request->setMethod('POST');
822+
$request->query->set('_method', array('delete', 'patch'));
823+
$this->assertSame('POST', $request->getMethod(), '->getMethod() returns the request method if invalid type is defined in query');
819824
}
820825

821826
/**

0 commit comments

Comments
 (0)