Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where Query parser ignored 0 strings #194

Merged
merged 1 commit into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Database/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public static function parse(string $filter): self
\array_pop($stack);
$stackCount--;

if (!empty($currentParam)) {
if (strlen($currentParam)) {
$currentArrayParam[] = $currentParam;
}

Expand All @@ -251,7 +251,7 @@ public static function parse(string $filter): self
} else {
// Append from parap builder. Either value, or array
if (empty($currentArrayParam)) {
if (!empty($currentParam)) {
if (strlen($currentParam)) {
$params[] = $currentParam;
}

Expand Down Expand Up @@ -650,7 +650,7 @@ public static function groupByType(array $queries): array
*
* @return Query[]
*/
public static function parseQueries(array $queries) : array
public static function parseQueries(array $queries): array
{
$parsed = [];
foreach ($queries as $query) {
Expand Down
19 changes: 17 additions & 2 deletions tests/Database/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,21 @@ public function testParseV2()
$this->assertEquals("attr", $query->getAttribute());
$this->assertEquals([1], $query->getValues());

$query = Query::parse('equal("attr", [0])');
$this->assertCount(1, $query->getValues());
$this->assertEquals("attr", $query->getAttribute());
$this->assertEquals([0], $query->getValues());

$query = Query::parse('equal("attr", 0,)');
christyjacob4 marked this conversation as resolved.
Show resolved Hide resolved
$this->assertCount(1, $query->getValues());
$this->assertEquals("attr", $query->getAttribute());
$this->assertEquals([0], $query->getValues());

$query = Query::parse('equal("attr", ["0"])');
$this->assertCount(1, $query->getValues());
$this->assertEquals("attr", $query->getAttribute());
$this->assertEquals(["0"], $query->getValues());

$query = Query::parse('equal(1, ["[Hello] World"])');
$this->assertCount(1, $query->getValues());
$this->assertEquals(1, $query->getAttribute());
Expand Down Expand Up @@ -247,7 +262,7 @@ public function testParseV2()
$this->assertCount(1, $query->getValues());
$this->assertEquals("value", $query->getAttribute());
$this->assertEquals('{"type":"json","somekey":"someval"}', $query->getValue());

$query = Query::parse('equal("value", "{ NormalStringInBraces }")');
$this->assertCount(1, $query->getValues());
$this->assertEquals("value", $query->getAttribute());
Expand Down Expand Up @@ -282,7 +297,7 @@ public function testParseV2()
$this->assertCount(1, $query->getValues());
$this->assertEquals("value", $query->getAttribute());
$this->assertEquals('DoubleQuote"InMiddle', $query->getValue());

$query = Query::parse('equal("value", "Slash/InMiddle")');
$this->assertCount(1, $query->getValues());
$this->assertEquals("value", $query->getAttribute());
Expand Down