Skip to content

Commit bd88f2f

Browse files
committed
Merge pull request #7976 in SW/shopware from ntr/5.6/fix-request-getparam-null-handling to 5.6
* commit '0c4aebb25aaa2fe45616c53ab181856d5b323092': NTR - Fix request getParam null handling
2 parents 5ef42e0 + 0c4aebb commit bd88f2f

File tree

2 files changed

+99
-2
lines changed

2 files changed

+99
-2
lines changed

engine/Library/Enlight/Controller/Request/RequestHttp.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,9 +739,13 @@ public function getParam($key, $default = null)
739739
{
740740
if (isset($this->_params[$key])) {
741741
return $this->_params[$key];
742-
} elseif ($this->query->has($key)) {
742+
}
743+
744+
if ($this->query->has($key) && $this->query->get($key) !== null) {
743745
return $this->query->get($key);
744-
} elseif ($this->request->has($key)) {
746+
}
747+
748+
if ($this->request->has($key) && $this->request->get($key) !== null) {
745749
return $this->request->get($key);
746750
}
747751

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
/**
3+
* Shopware 5
4+
* Copyright (c) shopware AG
5+
*
6+
* According to our dual licensing model, this program can be used either
7+
* under the terms of the GNU Affero General Public License, version 3,
8+
* or under a proprietary license.
9+
*
10+
* The texts of the GNU Affero General Public License with an additional
11+
* permission and of our proprietary license can be found at and
12+
* in the LICENSE file you have received along with this program.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* "Shopware" is a registered trademark of shopware AG.
20+
* The licensing of the program under the AGPLv3 does not imply a
21+
* trademark license. Therefore any rights, title and interest in
22+
* our trademarks remain entirely with us.
23+
*/
24+
25+
namespace Shopware\Tests\Unit\Library;
26+
27+
use PHPUnit\Framework\TestCase;
28+
use Shopware\Tests\Functional\Helper\Utils;
29+
30+
class RequestHttpTest extends TestCase
31+
{
32+
private $request;
33+
34+
public function setUp(): void
35+
{
36+
$this->request = new \Enlight_Controller_Request_RequestHttp();
37+
}
38+
39+
/**
40+
* @dataProvider getDataParamHandling
41+
*/
42+
public function testGetParamHandling($filled, $default, $expect): void
43+
{
44+
Utils::hijackProperty($this->request, '_params', ['foo' => $filled]);
45+
46+
static::assertEquals($expect, $this->request->getParam('foo', $default));
47+
48+
$this->request->request->set('foo', $filled);
49+
static::assertEquals($expect, $this->request->getParam('foo', $default));
50+
51+
$this->request->query->set('foo', $filled);
52+
static::assertEquals($expect, $this->request->getParam('foo', $default));
53+
}
54+
55+
public function getDataParamHandling(): array
56+
{
57+
return [
58+
[
59+
null,
60+
'foo',
61+
'foo',
62+
], [
63+
false,
64+
'foo',
65+
false,
66+
], [
67+
true,
68+
'foo',
69+
true,
70+
], [
71+
0,
72+
'foo',
73+
0,
74+
], [
75+
'0',
76+
'foo',
77+
'0',
78+
], [
79+
'false',
80+
'foo',
81+
'false',
82+
], [
83+
'true',
84+
'foo',
85+
'true',
86+
], [
87+
5.5,
88+
'foo',
89+
5.5,
90+
],
91+
];
92+
}
93+
}

0 commit comments

Comments
 (0)