Skip to content

Commit ffe81da

Browse files
committed
Close #196
1 parent 8932469 commit ffe81da

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/Http/Query/BaseQueryParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function getSorts(): iterable
133133
*/
134134
protected function splitString(string $paramName, $shouldBeString, string $separator): iterable
135135
{
136-
if (is_string($shouldBeString) === false || empty($trimmed = trim($shouldBeString)) === true) {
136+
if (is_string($shouldBeString) === false || ($trimmed = trim($shouldBeString)) === '') {
137137
throw new JsonApiException($this->createParameterError($paramName));
138138
}
139139

@@ -153,7 +153,7 @@ protected function splitStringAndCheckNoEmpties(string $paramName, $shouldBeStri
153153
{
154154
foreach ($this->splitString($paramName, $shouldBeString, $separator) as $value) {
155155
$trimmedValue = trim($value);
156-
if (empty($trimmedValue) === true) {
156+
if (($trimmedValue) === '') {
157157
throw new JsonApiException($this->createParameterError($paramName));
158158
}
159159

tests/Http/Query/BaseQueryParserTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,39 @@ public function testIncludes(): void
5555
], $this->iterableToArray($parser->getIncludes()));
5656
}
5757

58+
/**
59+
* That's a special case to test possible issues with `empty` function which thinks "0" is an empty string.
60+
*/
61+
public function testIncludesForStringWithZeroes1(): void
62+
{
63+
$queryParameters = [
64+
BaseQueryParser::PARAM_INCLUDE => '0',
65+
];
66+
67+
$parser = $this->createParser($queryParameters);
68+
69+
$this->assertEquals([
70+
'0' => ['0'],
71+
], $this->iterableToArray($parser->getIncludes()));
72+
}
73+
74+
/**
75+
* That's a special case to test possible issues with `empty` function which thinks "0" is an empty string.
76+
*/
77+
public function testIncludesForStringWithZeroes2(): void
78+
{
79+
$queryParameters = [
80+
BaseQueryParser::PARAM_INCLUDE => '0,1',
81+
];
82+
83+
$parser = $this->createParser($queryParameters);
84+
85+
$this->assertEquals([
86+
'0' => ['0'],
87+
'1' => ['1'],
88+
], $this->iterableToArray($parser->getIncludes()));
89+
}
90+
5891
/**
5992
* Test query.
6093
*/

0 commit comments

Comments
 (0)