Skip to content

Commit 6a4f475

Browse files
committed
CursorId should always serialize id as string
1 parent e0de6c9 commit 6a4f475

File tree

3 files changed

+55
-20
lines changed

3 files changed

+55
-20
lines changed

src/MongoDB/CursorId.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,7 @@ static HashTable* php_phongo_cursorid_get_properties_hash(phongo_compat_object_h
7575
zval value;
7676

7777
if (is_serialize) {
78-
if (intern->id > INT32_MAX || intern->id < INT32_MIN) {
79-
ZVAL_INT64_STRING(&value, intern->id);
80-
} else {
81-
ZVAL_LONG(&value, intern->id);
82-
}
78+
ZVAL_INT64_STRING(&value, intern->id);
8379
} else {
8480
#if SIZEOF_ZEND_LONG == 4
8581
if (intern->id > INT32_MAX || intern->id < INT32_MIN) {

tests/cursorid/cursorid-serialization-001.phpt

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,43 @@ MongoDB\Driver\CursorId serialization (Serializable interface)
88

99
require_once __DIR__ . "/../utils/basic.inc";
1010

11-
$serialized = 'C:23:"MongoDB\Driver\CursorId":42:{a:1:{s:2:"id";s:19:"7250031947823432848";}}';
11+
$tests = [
12+
unserialize('C:23:"MongoDB\Driver\CursorId":42:{a:1:{s:2:"id";s:19:"7250031947823432848";}}'),
13+
unserialize('C:23:"MongoDB\Driver\CursorId":23:{a:1:{s:2:"id";s:1:"0";}}'),
14+
];
1215

13-
$cursorId = unserialize($serialized);
14-
15-
var_dump($cursorId);
16-
var_dump($cursorId instanceof Serializable);
17-
echo serialize($cursorId), "\n";
16+
foreach ($tests as $test) {
17+
var_dump($test);
18+
var_dump($test instanceof Serializable);
19+
echo $s = serialize($test), "\n";
20+
var_dump(unserialize($s));
21+
echo "\n";
22+
}
1823

1924
?>
2025
===DONE===
2126
<?php exit(0); ?>
2227
--EXPECTF--
2328
object(MongoDB\Driver\CursorId)#%d (%d) {
2429
["id"]=>
25-
%rint\(\d+\)|string\(\d+\) "\d+"%r
30+
%rint\(7250031947823432848\)|string\(19\) "7250031947823432848"%r
2631
}
2732
bool(true)
2833
C:23:"MongoDB\Driver\CursorId":42:{a:1:{s:2:"id";s:19:"7250031947823432848";}}
34+
object(MongoDB\Driver\CursorId)#%d (%d) {
35+
["id"]=>
36+
%rint\(7250031947823432848\)|string\(19\) "7250031947823432848"%r
37+
}
38+
39+
object(MongoDB\Driver\CursorId)#%d (%d) {
40+
["id"]=>
41+
int(0)
42+
}
43+
bool(true)
44+
C:23:"MongoDB\Driver\CursorId":23:{a:1:{s:2:"id";s:1:"0";}}
45+
object(MongoDB\Driver\CursorId)#%d (%d) {
46+
["id"]=>
47+
int(0)
48+
}
49+
2950
===DONE===

tests/cursorid/cursorid-serialization-002.phpt

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,40 @@ MongoDB\Driver\CursorId serialization (__serialize and __unserialize)
88

99
require_once __DIR__ . "/../utils/basic.inc";
1010

11-
$serialized = 'O:23:"MongoDB\Driver\CursorId":1:{s:2:"id";s:19:"7250031947823432848";}';
11+
$tests = [
12+
unserialize('O:23:"MongoDB\Driver\CursorId":1:{s:2:"id";s:19:"7250031947823432848";}'),
13+
unserialize('O:23:"MongoDB\Driver\CursorId":1:{s:2:"id";s:1:"0";}'),
14+
];
1215

13-
$cursorId = unserialize($serialized);
14-
15-
var_dump($cursorId);
16-
var_dump($cursorId instanceof Serializable);
17-
echo serialize($cursorId), "\n";
16+
foreach ($tests as $test) {
17+
var_dump($test);
18+
echo $s = serialize($test), "\n";
19+
var_dump(unserialize($s));
20+
echo "\n";
21+
}
1822

1923
?>
2024
===DONE===
2125
<?php exit(0); ?>
2226
--EXPECTF--
2327
object(MongoDB\Driver\CursorId)#%d (%d) {
2428
["id"]=>
25-
%rint\(\d+\)|string\(\d+\) "\d+"%r
29+
%rint\(7250031947823432848\)|string\(19\) "7250031947823432848"%r
2630
}
27-
bool(true)
2831
O:23:"MongoDB\Driver\CursorId":1:{s:2:"id";s:19:"7250031947823432848";}
32+
object(MongoDB\Driver\CursorId)#%d (%d) {
33+
["id"]=>
34+
%rint\(7250031947823432848\)|string\(19\) "7250031947823432848"%r
35+
}
36+
37+
object(MongoDB\Driver\CursorId)#%d (%d) {
38+
["id"]=>
39+
int(0)
40+
}
41+
O:23:"MongoDB\Driver\CursorId":1:{s:2:"id";s:1:"0";}
42+
object(MongoDB\Driver\CursorId)#%d (%d) {
43+
["id"]=>
44+
int(0)
45+
}
46+
2947
===DONE===

0 commit comments

Comments
 (0)