Skip to content

Commit 91da0ce

Browse files
author
Jan Steemann
committed
issue arangodb#176: bug; Invalid bind parameter value on "file" value
1 parent 7ddd919 commit 91da0ce

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

lib/triagens/ArangoDb/ValueValidator.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class ValueValidator
3333
*/
3434
public static function validate($value)
3535
{
36+
if (is_string($value) || is_int($value) || is_double($value) || is_bool($value) || is_null($value)) {
37+
// type is allowed
38+
return;
39+
}
40+
3641
if (is_array($value)) {
3742
// must check all elements contained
3843
foreach ($value as $subValue) {
@@ -41,10 +46,6 @@ public static function validate($value)
4146

4247
return;
4348
}
44-
else if (! is_object($value) && ! is_resource($value) && ! is_callable($value)) {
45-
// type is allowed
46-
return;
47-
}
4849

4950
// type is invalid
5051
throw new ClientException('Invalid bind parameter value');

tests/StatementTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,55 @@ public function testStatementWithFullCount()
242242
$this->assertEquals(3, $cursor->getFullCount(), "The fullCount should be 3");
243243
}
244244

245+
246+
public function testBindReservedValue()
247+
{
248+
$connection = $this->connection;
249+
$collection = $this->collection;
250+
251+
$documentHandler = new DocumentHandler($connection);
252+
253+
$document = new Document();
254+
$document->file = 'testFooBar';
255+
$documentHandler->add($collection->getId(), $document);
256+
257+
$statement = new Statement($connection, array(
258+
"query" => 'FOR a IN `ArangoDB_PHP_TestSuite_TestCollection_01` FILTER a.file == @file RETURN a.file',
259+
"bindVars" => array("file" => "testFooBar"),
260+
"_sanitize" => true
261+
));
262+
263+
$cursor = $statement->execute();
264+
265+
$rows = $cursor->getAll();
266+
$this->assertEquals("testFooBar", $rows[0]);
267+
}
268+
269+
270+
public function testBindReservedName()
271+
{
272+
$connection = $this->connection;
273+
$collection = $this->collection;
274+
275+
$documentHandler = new DocumentHandler($connection);
276+
277+
$document = new Document();
278+
$document->test = 'file';
279+
$documentHandler->add($collection->getId(), $document);
280+
281+
$statement = new Statement($connection, array(
282+
"query" => 'FOR a IN `ArangoDB_PHP_TestSuite_TestCollection_01` FILTER a.test == @test RETURN a.test',
283+
"bindVars" => array("test" => "file"),
284+
"_sanitize" => true
285+
));
286+
287+
$cursor = $statement->execute();
288+
289+
$rows = $cursor->getAll();
290+
$this->assertEquals("file", $rows[0]);
291+
}
292+
293+
245294
public function tearDown()
246295
{
247296
try {

0 commit comments

Comments
 (0)