Skip to content

Commit

Permalink
Merge pull request #4 from BaguettePHP/feature/accept-zero
Browse files Browse the repository at this point in the history
Accept 0 as @int value
  • Loading branch information
zonuexe authored Aug 22, 2019
2 parents 8add876 + 9d802e7 commit 0bf12ff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ protected static function replaceHolder($pdo, $key, $type, $value, &$bind_values
throw new \DomainException(sprintf('param "%s" is integer out of range.', $key));
}

if (!preg_match('/\A-?[1-9][0-9]*\z/', $s)) {
$is_zero = $s === 0 || $s === '0';

if (!$is_zero && !preg_match('/\A-?[1-9][0-9]*\z/', $s)) {
throw new \DomainException();
}

Expand Down
6 changes: 4 additions & 2 deletions tests/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ final class QueryTest extends \PHPUnit\Framework\TestCase
public function test()
{
$pdo = new DummyPDO;
$orig = "string: :a@string\nint :b@int\nstring: :a@string\nint :b@int";
$orig = "string: :a@string\nint :b@int\nstring: :a@string\nint :b@int\nint :c1@int\nint :c1@int";
$stmt = Query::build($pdo, $orig, [
':a' => 'AAAA',
':b' => '2222',
':c1' => '0',
':c2' => 0,
]);
$expected = 'string: @AAAA@ int 2222 string: @AAAA@ int 2222';
$expected = 'string: @AAAA@ int 2222 string: @AAAA@ int 2222 int 0 int 0';
$this->assertSame($expected, $stmt->queryString);
}
}

0 comments on commit 0bf12ff

Please sign in to comment.