From e341c2d7dae5f34f17649084bd63159b8cfa2bfd Mon Sep 17 00:00:00 2001 From: Bas de Groot Date: Wed, 18 Nov 2020 08:16:20 +0100 Subject: [PATCH] Fixed validation of numeric strings. These will and must be strictly handled as strings to support a numeric string _key. --- .github/workflows/coverage.yml | 2 +- src/Traits/ValidatesExpressions.php | 2 +- tests/Unit/AQL/OperatorExpressionsTest.php | 2 +- tests/Unit/GrammarTest.php | 3 +++ 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 245adc3..c1f4e2c 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -13,7 +13,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '7.2' + php-version: '7.4' extensions: mbstring, intl ini-values: post_max_size=256M, short_open_tag=On coverage: xdebug diff --git a/src/Traits/ValidatesExpressions.php b/src/Traits/ValidatesExpressions.php index 6d29491..46185c8 100644 --- a/src/Traits/ValidatesExpressions.php +++ b/src/Traits/ValidatesExpressions.php @@ -79,7 +79,7 @@ public function isNull($value): bool */ public function isNumber($value): bool { - return is_numeric($value); + return is_numeric($value) && !is_string($value); } /** diff --git a/tests/Unit/AQL/OperatorExpressionsTest.php b/tests/Unit/AQL/OperatorExpressionsTest.php index 23655af..a20365c 100644 --- a/tests/Unit/AQL/OperatorExpressionsTest.php +++ b/tests/Unit/AQL/OperatorExpressionsTest.php @@ -14,7 +14,7 @@ class OperatorExpressionsTest extends TestCase public function testIf() { $qb = new QueryBuilder(); - $qb->let('x', 5)->return($qb->if(['x', '==', '5'], true, false)); + $qb->let('x', 5)->return($qb->if(['x', '==', 5], true, false)); self::assertEquals("LET x = 5 RETURN (x == 5) ? true : false", $qb->get()->query); } diff --git a/tests/Unit/GrammarTest.php b/tests/Unit/GrammarTest.php index 60e9498..38ebc78 100644 --- a/tests/Unit/GrammarTest.php +++ b/tests/Unit/GrammarTest.php @@ -293,6 +293,9 @@ public function testIsNumeric() $result = $this->grammar->isNumber('string'); self::assertFalse($result); + + $result = $this->grammar->isNumber('1'); + self::assertFalse($result); } public function testFormatBind()