|
| 1 | +--TEST-- |
| 2 | +BSON\fromPHP(): PHP documents with null bytes in field name |
| 3 | +--FILE-- |
| 4 | +<?php |
| 5 | + |
| 6 | +require_once __DIR__ . '/../utils/tools.php'; |
| 7 | + |
| 8 | +echo "\nTesting array with one leading null byte in field name\n"; |
| 9 | +hex_dump(fromPHP(["\0" => 1])); |
| 10 | + |
| 11 | +echo "\nTesting array with one trailing null byte in field name\n"; |
| 12 | +hex_dump(fromPHP(["a\0" => 1])); |
| 13 | + |
| 14 | +echo "\nTesting array with multiple null bytes in field name\n"; |
| 15 | +hex_dump(fromPHP(["\0\0\0" => 1])); |
| 16 | + |
| 17 | +/* Per PHPC-884, field names with a leading null byte are ignored when encoding |
| 18 | + * a document from an object's property hash table, since PHP uses leading bytes |
| 19 | + * to denote protected and private properties. */ |
| 20 | +echo "\nTesting object with one leading null byte in field name\n"; |
| 21 | +hex_dump(fromPHP((object) ["\0" => 1])); |
| 22 | + |
| 23 | +echo "\nTesting object with one trailing null byte in field name\n"; |
| 24 | +hex_dump(fromPHP((object) ["a\0" => 1])); |
| 25 | + |
| 26 | +echo "\nTesting object with multiple null bytes in field name\n"; |
| 27 | +hex_dump(fromPHP((object) ["\0\0\0" => 1])); |
| 28 | + |
| 29 | +?> |
| 30 | +===DONE=== |
| 31 | +<?php exit(0); ?> |
| 32 | +--EXPECT-- |
| 33 | +Testing array with one leading null byte in field name |
| 34 | + 0 : 0b 00 00 00 10 00 01 00 00 00 00 [...........] |
| 35 | + |
| 36 | +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......] |
| 38 | + |
| 39 | +Testing array with multiple null bytes in field name |
| 40 | + 0 : 0b 00 00 00 10 00 01 00 00 00 00 [...........] |
| 41 | + |
| 42 | +Testing object with one leading null byte in field name |
| 43 | + 0 : 05 00 00 00 00 [.....] |
| 44 | + |
| 45 | +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......] |
| 47 | + |
| 48 | +Testing object with multiple null bytes in field name |
| 49 | + 0 : 05 00 00 00 00 [.....] |
| 50 | +===DONE=== |
0 commit comments