-
Notifications
You must be signed in to change notification settings - Fork 208
PHPC-1748 Fix wrong return value of Cursor::key when iterator is not valid #1192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,11 @@ static int php_phongo_cursor_valid(php_phongo_cursor_t* cursor) /* {{{ */ | |
|
||
static void php_phongo_cursor_get_current_key(php_phongo_cursor_t* cursor, zval* key) /* {{{ */ | ||
{ | ||
if (Z_ISUNDEF(cursor->visitor_data.zchild)) { | ||
ZVAL_NULL(key); | ||
return; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you introduced the Iterator methods, it looks like That would allow you to move this logic into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I can refactor this 👍 |
||
ZVAL_LONG(key, cursor->current); | ||
} /* }}} */ | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--TEST-- | ||
MongoDB\Driver\Cursor handles invalid positions gracefully | ||
--SKIPIF-- | ||
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?> | ||
<?php skip_if_not_live(); ?> | ||
<?php skip_if_not_clean(); ?> | ||
--FILE-- | ||
<?php | ||
require_once __DIR__ . "/../utils/basic.inc"; | ||
|
||
$manager = new MongoDB\Driver\Manager(URI); | ||
|
||
$bulkWrite = new MongoDB\Driver\BulkWrite; | ||
$bulkWrite->insert(array('_id' => 0)); | ||
|
||
$writeResult = $manager->executeBulkWrite(NS, $bulkWrite); | ||
|
||
$cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query(array())); | ||
|
||
$cursor->rewind(); | ||
var_dump($cursor->valid()); | ||
var_dump($cursor->key()); | ||
var_dump($cursor->current()); | ||
|
||
$cursor->next(); | ||
var_dump($cursor->valid()); | ||
var_dump($cursor->key()); | ||
var_dump($cursor->current()); | ||
|
||
?> | ||
===DONE=== | ||
<?php exit(0); ?> | ||
--EXPECTF-- | ||
bool(true) | ||
int(0) | ||
object(stdClass)#%d (1) { | ||
["_id"]=> | ||
int(0) | ||
} | ||
bool(false) | ||
NULL | ||
NULL | ||
===DONE=== |
Uh oh!
There was an error while loading. Please reload this page.