Skip to content

Commit

Permalink
Fix bugs where Query parser ignored 0 strings
Browse files Browse the repository at this point in the history
  • Loading branch information
stnguyen90 committed Sep 30, 2022
1 parent 2883de8 commit 4e34926
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
7 changes: 4 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,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;
}

Expand Down Expand Up @@ -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) {
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,)');
$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

0 comments on commit 4e34926

Please sign in to comment.