From 4e34926aa9436ef9c5aa3a14be9ece012abc3daf Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Fri, 23 Sep 2022 00:08:53 +0000 Subject: [PATCH] Fix bugs where Query parser ignored 0 strings --- src/Database/Query.php | 7 ++++--- tests/Database/QueryTest.php | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Database/Query.php b/src/Database/Query.php index 590029cf1..f37db0011 100644 --- a/src/Database/Query.php +++ b/src/Database/Query.php @@ -234,7 +234,7 @@ public static function parse(string $filter): self \array_pop($stack); $stackCount--; - if (!empty($currentParam)) { + if (strlen($currentParam)) { $currentArrayParam[] = $currentParam; } @@ -251,7 +251,8 @@ 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)) { + var_dump($currentParam); $params[] = $currentParam; } @@ -650,7 +651,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) { diff --git a/tests/Database/QueryTest.php b/tests/Database/QueryTest.php index bf629258e..9f3dd10c8 100644 --- a/tests/Database/QueryTest.php +++ b/tests/Database/QueryTest.php @@ -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,)'); + $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()); @@ -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()); @@ -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());