@@ -6,13 +6,19 @@ BSON\fromPHP(): PHP documents with null bytes in field name
6
6
require_once __DIR__ . '/../utils/tools.php ' ;
7
7
8
8
echo "\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" ;
10
12
11
13
echo "\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" ;
13
17
14
18
echo "\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" ;
16
22
17
23
/* Per PHPC-884, field names with a leading null byte are ignored when encoding
18
24
* 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";
21
27
hex_dump (fromPHP ((object ) ["\0" => 1 ]));
22
28
23
29
echo "\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" ;
25
33
26
34
echo "\nTesting object with multiple null bytes in field name \n" ;
27
35
hex_dump (fromPHP ((object ) ["\0\0\0" => 1 ]));
@@ -31,19 +39,23 @@ hex_dump(fromPHP((object) ["\0\0\0" => 1]));
31
39
<?php exit (0 ); ?>
32
40
--EXPECT--
33
41
Testing 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 "".
35
44
36
45
Testing 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".
38
48
39
49
Testing 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 "".
41
52
42
53
Testing object with one leading null byte in field name
43
54
0 : 05 00 00 00 00 [.....]
44
55
45
56
Testing 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".
47
59
48
60
Testing object with multiple null bytes in field name
49
61
0 : 05 00 00 00 00 [.....]
0 commit comments