Files
mongo-php-driver/tests/bson/bson-fromPHP_error-006.phpt
T
Jeremy Mikola 93bd10bd21 PHPC-1897: Test serialization of BSON with embedded null bytes in strings (#1255)
* BSON corpus prose tests for null bytes

For tests that already existed we just add a reference to the prose test

* BSON corpus tests for null bytes

Synced with mongodb/specifications@c64fc79899

This sync also removes some old DBRef tests, which should have been removed in 6929bcb608.

* Bump libmongoc to 1.19.1 to pull in changes from CDRIVER-4083
2021-10-25 13:27:33 -04:00

59 lines
2.1 KiB
PHP

--TEST--
MongoDB\BSON\fromPHP(): PHP documents with null bytes in field name
--DESCRIPTION--
BSON Corpus spec prose test #1
--FILE--
<?php
require_once __DIR__ . '/../utils/basic.inc';
echo "\nTesting array with one leading null byte in field name\n";
echo throws(function() {
fromPHP(["\0" => 1]);
}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n";
echo "\nTesting array with one trailing null byte in field name\n";
echo throws(function() {
fromPHP(["a\0" => 1]);
}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n";
echo "\nTesting array with multiple null bytes in field name\n";
echo throws(function() {
fromPHP(["\0\0\0" => 1]);
}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n";
echo "\nTesting object with one trailing null byte in field name\n";
echo throws(function() {
fromPHP((object) ["a\0" => 1]);
}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n";
echo "\nTesting nested array with one trailing null byte in field name\n";
echo throws(function() {
fromPHP(['a' => ["b\0" => 1]]);
}, 'MongoDB\Driver\Exception\UnexpectedValueException'), "\n";
?>
===DONE===
<?php exit(0); ?>
--EXPECT--
Testing array with one leading null byte in field name
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
BSON keys cannot contain null bytes. Unexpected null byte after "".
Testing array with one trailing null byte in field name
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
BSON keys cannot contain null bytes. Unexpected null byte after "a".
Testing array with multiple null bytes in field name
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
BSON keys cannot contain null bytes. Unexpected null byte after "".
Testing object with one trailing null byte in field name
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
BSON keys cannot contain null bytes. Unexpected null byte after "a".
Testing nested array with one trailing null byte in field name
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
BSON keys cannot contain null bytes. Unexpected null byte after "b".
===DONE===