@@ -6,13 +6,19 @@ BSON\fromPHP(): PHP documents with null bytes in field name
66require_once __DIR__ . '/../utils/tools.php ' ;
77
88echo "\nTesting array with one leading null byte in field name \n" ;
9- hex_dump (fromPHP (["\0" => 1 ]));
9+ echo throws (function () {
10+ fromPHP (["\0" => 1 ]);
11+ }, 'MongoDB\Driver\Exception\UnexpectedValueException ' ), "\n" ;
1012
1113echo "\nTesting array with one trailing null byte in field name \n" ;
12- hex_dump (fromPHP (["a \0" => 1 ]));
14+ echo throws (function () {
15+ fromPHP (["a \0" => 1 ]);
16+ }, 'MongoDB\Driver\Exception\UnexpectedValueException ' ), "\n" ;
1317
1418echo "\nTesting array with multiple null bytes in field name \n" ;
15- hex_dump (fromPHP (["\0\0\0" => 1 ]));
19+ echo throws (function () {
20+ fromPHP (["\0\0\0" => 1 ]);
21+ }, 'MongoDB\Driver\Exception\UnexpectedValueException ' ), "\n" ;
1622
1723/* Per PHPC-884, field names with a leading null byte are ignored when encoding
1824 * a document from an object's property hash table, since PHP uses leading bytes
@@ -21,7 +27,9 @@ echo "\nTesting object with one leading null byte in field name\n";
2127hex_dump (fromPHP ((object ) ["\0" => 1 ]));
2228
2329echo "\nTesting object with one trailing null byte in field name \n" ;
24- hex_dump (fromPHP ((object ) ["a \0" => 1 ]));
30+ echo throws (function () {
31+ fromPHP ((object ) ["a \0" => 1 ]);
32+ }, 'MongoDB\Driver\Exception\UnexpectedValueException ' ), "\n" ;
2533
2634echo "\nTesting object with multiple null bytes in field name \n" ;
2735hex_dump (fromPHP ((object ) ["\0\0\0" => 1 ]));
@@ -31,19 +39,23 @@ hex_dump(fromPHP((object) ["\0\0\0" => 1]));
3139<?php exit (0 ); ?>
3240--EXPECT--
3341Testing array with one leading null byte in field name
34- 0 : 0b 00 00 00 10 00 01 00 00 00 00 [...........]
42+ OK: Got MongoDB\Driver\Exception\UnexpectedValueException
43+ BSON keys cannot contain null bytes. Unexpected null byte after "".
3544
3645Testing array with one trailing null byte in field name
37- 0 : 0c 00 00 00 10 61 00 01 00 00 00 00 [.....a......]
46+ OK: Got MongoDB\Driver\Exception\UnexpectedValueException
47+ BSON keys cannot contain null bytes. Unexpected null byte after "a".
3848
3949Testing array with multiple null bytes in field name
40- 0 : 0b 00 00 00 10 00 01 00 00 00 00 [...........]
50+ OK: Got MongoDB\Driver\Exception\UnexpectedValueException
51+ BSON keys cannot contain null bytes. Unexpected null byte after "".
4152
4253Testing object with one leading null byte in field name
4354 0 : 05 00 00 00 00 [.....]
4455
4556Testing object with one trailing null byte in field name
46- 0 : 0c 00 00 00 10 61 00 01 00 00 00 00 [.....a......]
57+ OK: Got MongoDB\Driver\Exception\UnexpectedValueException
58+ BSON keys cannot contain null bytes. Unexpected null byte after "a".
4759
4860Testing object with multiple null bytes in field name
4961 0 : 05 00 00 00 00 [.....]
0 commit comments