@@ -5,58 +5,22 @@ BSON\fromPHP(): PHP documents with null bytes in field name
5
5
6
6
require_once __DIR__ . '/../utils/tools.php ' ;
7
7
8
- echo "\nTesting array with one leading null byte in field name \n" ;
9
- echo throws (function () {
10
- fromPHP (["\0" => 1 ]);
11
- }, 'MongoDB\Driver\Exception\UnexpectedValueException ' ), "\n" ;
12
-
13
- echo "\nTesting array with one trailing null byte in field name \n" ;
14
- echo throws (function () {
15
- fromPHP (["a \0" => 1 ]);
16
- }, 'MongoDB\Driver\Exception\UnexpectedValueException ' ), "\n" ;
17
-
18
- echo "\nTesting array with multiple null bytes in field name \n" ;
19
- echo throws (function () {
20
- fromPHP (["\0\0\0" => 1 ]);
21
- }, 'MongoDB\Driver\Exception\UnexpectedValueException ' ), "\n" ;
22
-
23
8
/* Per PHPC-884, field names with a leading null byte are ignored when encoding
24
9
* a document from an object's property hash table, since PHP uses leading bytes
25
10
* to denote protected and private properties. */
26
11
echo "\nTesting object with one leading null byte in field name \n" ;
27
12
hex_dump (fromPHP ((object ) ["\0" => 1 ]));
28
13
29
- echo "\nTesting object with one trailing null byte in field name \n" ;
30
- echo throws (function () {
31
- fromPHP ((object ) ["a \0" => 1 ]);
32
- }, 'MongoDB\Driver\Exception\UnexpectedValueException ' ), "\n" ;
33
-
34
14
echo "\nTesting object with multiple null bytes in field name \n" ;
35
15
hex_dump (fromPHP ((object ) ["\0\0\0" => 1 ]));
36
16
37
17
?>
38
18
===DONE===
39
19
<?php exit (0 ); ?>
40
20
--EXPECT--
41
- Testing array with one leading null byte in field name
42
- OK: Got MongoDB\Driver\Exception\UnexpectedValueException
43
- BSON keys cannot contain null bytes. Unexpected null byte after "".
44
-
45
- Testing array with one trailing null byte in field name
46
- OK: Got MongoDB\Driver\Exception\UnexpectedValueException
47
- BSON keys cannot contain null bytes. Unexpected null byte after "a".
48
-
49
- Testing array with multiple null bytes in field name
50
- OK: Got MongoDB\Driver\Exception\UnexpectedValueException
51
- BSON keys cannot contain null bytes. Unexpected null byte after "".
52
-
53
21
Testing object with one leading null byte in field name
54
22
0 : 05 00 00 00 00 [.....]
55
23
56
- Testing object with one trailing null byte in field name
57
- OK: Got MongoDB\Driver\Exception\UnexpectedValueException
58
- BSON keys cannot contain null bytes. Unexpected null byte after "a".
59
-
60
24
Testing object with multiple null bytes in field name
61
25
0 : 05 00 00 00 00 [.....]
62
26
===DONE===
0 commit comments