Skip to content

Commit 70a097e

Browse files
authored
PHPC-1713: Ensure Cursor::current returns null on invalid positions (#1186)
* Ensure Cursor::current returns null on invalid positions * Addressed code review feedback
1 parent 90a57cd commit 70a097e

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/MongoDB/Cursor.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,9 @@ PHP_METHOD(Cursor, current)
311311

312312
data = php_phongo_cursor_get_current_data(intern);
313313

314-
if (data) {
314+
if (Z_ISUNDEF_P(data)) {
315+
RETURN_NULL();
316+
} else {
315317
ZVAL_COPY_DEREF(return_value, data);
316318
}
317319
}

tests/cursor/bug1713-001.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
PHPC-1713: MongoDB\Driver\Cursor::current() does not return anything
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_live(); ?>
6+
--FILE--
7+
<?php
8+
require_once __DIR__ . "/../utils/basic.inc";
9+
10+
$manager = new MongoDB\Driver\Manager(URI);
11+
12+
$cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query([]));
13+
14+
var_dump($cursor->valid());
15+
var_dump($cursor->current());
16+
17+
?>
18+
===DONE===
19+
<?php exit(0); ?>
20+
--EXPECTF--
21+
bool(false)
22+
NULL
23+
===DONE===

0 commit comments

Comments
 (0)