@@ -5,58 +5,22 @@ BSON\fromPHP(): PHP documents with null bytes in field name
55
66require_once __DIR__ . '/../utils/tools.php ' ;
77
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-
238/* Per PHPC-884, field names with a leading null byte are ignored when encoding
249 * a document from an object's property hash table, since PHP uses leading bytes
2510 * to denote protected and private properties. */
2611echo "\nTesting object with one leading null byte in field name \n" ;
2712hex_dump (fromPHP ((object ) ["\0" => 1 ]));
2813
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-
3414echo "\nTesting object with multiple null bytes in field name \n" ;
3515hex_dump (fromPHP ((object ) ["\0\0\0" => 1 ]));
3616
3717?>
3818===DONE===
3919<?php exit (0 ); ?>
4020--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-
5321Testing object with one leading null byte in field name
5422 0 : 05 00 00 00 00 [.....]
5523
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-
6024Testing object with multiple null bytes in field name
6125 0 : 05 00 00 00 00 [.....]
6226===DONE===
0 commit comments