Skip to content

Commit 1ca7859

Browse files
Merge pull request #2447 from yolcuiskender/keepnumericalindexes
array_merge was re-indexing arrays with numerical index
2 parents 8e43e5d + d640b57 commit 1ca7859

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Slim/Http/Request.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,7 @@ public function getParams(array $only = null)
12111211
$params = $this->getQueryParams();
12121212
$postParams = $this->getParsedBody();
12131213
if ($postParams) {
1214-
$params = array_merge($params, (array)$postParams);
1214+
$params = array_replace($params, (array)$postParams);
12151215
}
12161216

12171217
if ($only) {

tests/Http/RequestTest.php

+20
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,26 @@ public function testCreateFromEnvironmentWithMultipart()
213213
$this->assertEquals(['foo' => 'bar'], $request->getParsedBody());
214214
}
215215

216+
public function testCreateFromEnvironmentWithMultipartAndQueryParams()
217+
{
218+
$_POST['123'] = 'bar';
219+
220+
$env = Environment::mock([
221+
'SCRIPT_NAME' => '/index.php',
222+
'REQUEST_URI' => '/foo',
223+
'REQUEST_METHOD' => 'POST',
224+
'QUERY_STRING' => '123=zar',
225+
'HTTP_CONTENT_TYPE' => 'multipart/form-data; boundary=---foo'
226+
]);
227+
228+
$request = Request::createFromEnvironment($env);
229+
unset($_POST);
230+
231+
# Fixes the bug that would make it previously return [ 0 => 'bar' ]
232+
$this->assertEquals(['123' => 'bar'], $request->getParams());
233+
$this->assertEquals(['123' => 'zar'], $request->getQueryParams());
234+
}
235+
216236
/**
217237
* @covers Slim\Http\Request::createFromEnvironment
218238
*/

0 commit comments

Comments
 (0)