Skip to content

PHPC-1681 Support parsing $uuid as extended JSON representation for subtype 4 binary #1208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ if test "$PHP_MONGODB" != "no"; then
PHP_MONGODB_JSONSL_SOURCES="jsonsl.c"

dnl Generated with: find src/libmongoc/src/libmongoc/src/mongoc -name '*.c' -print0 | cut -sz -d / -f 7- | sort -dz | tr '\000' ' '
PHP_MONGODB_MONGOC_SOURCES="mongoc-aggregate.c mongoc-apm.c mongoc-array.c mongoc-async.c mongoc-async-cmd.c mongoc-buffer.c mongoc-bulk-operation.c mongoc-change-stream.c mongoc-client.c mongoc-client-pool.c mongoc-client-session.c mongoc-client-side-encryption.c mongoc-cluster-aws.c mongoc-cluster.c mongoc-cluster-cyrus.c mongoc-cluster-sasl.c mongoc-cluster-sspi.c mongoc-cmd.c mongoc-collection.c mongoc-compression.c mongoc-counters.c mongoc-crypt.c mongoc-crypto.c mongoc-crypto-cng.c mongoc-crypto-common-crypto.c mongoc-crypto-openssl.c mongoc-cursor-array.c mongoc-cursor.c mongoc-cursor-change-stream.c mongoc-cursor-cmd.c mongoc-cursor-cmd-deprecated.c mongoc-cursor-find.c mongoc-cursor-find-cmd.c mongoc-cursor-find-opquery.c mongoc-cursor-legacy.c mongoc-cyrus.c mongoc-database.c mongoc-error.c mongoc-find-and-modify.c mongoc-gridfs-bucket.c mongoc-gridfs-bucket-file.c mongoc-gridfs.c mongoc-gridfs-file.c mongoc-gridfs-file-list.c mongoc-gridfs-file-page.c mongoc-handshake.c mongoc-host-list.c mongoc-http.c mongoc-index.c mongoc-init.c mongoc-interrupt.c mongoc-libressl.c mongoc-linux-distro-scanner.c mongoc-list.c mongoc-log.c mongoc-matcher.c mongoc-matcher-op.c mongoc-memcmp.c mongoc-ocsp-cache.c mongoc-openssl.c mongoc-opts.c mongoc-opts-helpers.c mongoc-queue.c mongoc-rand-cng.c mongoc-rand-common-crypto.c mongoc-rand-openssl.c mongoc-read-concern.c mongoc-read-prefs.c mongoc-rpc.c mongoc-sasl.c mongoc-scram.c mongoc-secure-channel.c mongoc-secure-transport.c mongoc-server-api.c mongoc-server-description.c mongoc-server-monitor.c mongoc-server-stream.c mongoc-set.c mongoc-socket.c mongoc-ssl.c mongoc-sspi.c mongoc-stream-buffered.c mongoc-stream.c mongoc-stream-file.c mongoc-stream-gridfs.c mongoc-stream-gridfs-download.c mongoc-stream-gridfs-upload.c mongoc-stream-socket.c mongoc-stream-tls.c mongoc-stream-tls-libressl.c mongoc-stream-tls-openssl-bio.c mongoc-stream-tls-openssl.c mongoc-stream-tls-secure-channel.c mongoc-stream-tls-secure-transport.c mongoc-timeout.c mongoc-topology-background-monitoring.c mongoc-topology.c mongoc-topology-description-apm.c mongoc-topology-description.c mongoc-topology-scanner.c mongoc-uri.c mongoc-util.c mongoc-version-functions.c mongoc-write-command.c mongoc-write-command-legacy.c mongoc-write-concern.c"
PHP_MONGODB_MONGOC_SOURCES="mongoc-aggregate.c mongoc-apm.c mongoc-array.c mongoc-async.c mongoc-async-cmd.c mongoc-buffer.c mongoc-bulk-operation.c mongoc-change-stream.c mongoc-client.c mongoc-client-pool.c mongoc-client-session.c mongoc-client-side-encryption.c mongoc-cluster-aws.c mongoc-cluster.c mongoc-cluster-cyrus.c mongoc-cluster-sasl.c mongoc-cluster-sspi.c mongoc-cmd.c mongoc-collection.c mongoc-compression.c mongoc-counters.c mongoc-crypt.c mongoc-crypto.c mongoc-crypto-cng.c mongoc-crypto-common-crypto.c mongoc-crypto-openssl.c mongoc-cursor-array.c mongoc-cursor.c mongoc-cursor-change-stream.c mongoc-cursor-cmd.c mongoc-cursor-cmd-deprecated.c mongoc-cursor-find.c mongoc-cursor-find-cmd.c mongoc-cursor-find-opquery.c mongoc-cursor-legacy.c mongoc-cyrus.c mongoc-database.c mongoc-error.c mongoc-find-and-modify.c mongoc-gridfs-bucket.c mongoc-gridfs-bucket-file.c mongoc-gridfs.c mongoc-gridfs-file.c mongoc-gridfs-file-list.c mongoc-gridfs-file-page.c mongoc-handshake.c mongoc-host-list.c mongoc-http.c mongoc-index.c mongoc-init.c mongoc-interrupt.c mongoc-libressl.c mongoc-linux-distro-scanner.c mongoc-list.c mongoc-log.c mongoc-matcher.c mongoc-matcher-op.c mongoc-memcmp.c mongoc-ocsp-cache.c mongoc-openssl.c mongoc-optional.c mongoc-opts.c mongoc-opts-helpers.c mongoc-queue.c mongoc-rand-cng.c mongoc-rand-common-crypto.c mongoc-rand-openssl.c mongoc-read-concern.c mongoc-read-prefs.c mongoc-rpc.c mongoc-sasl.c mongoc-scram.c mongoc-secure-channel.c mongoc-secure-transport.c mongoc-server-api.c mongoc-server-description.c mongoc-server-monitor.c mongoc-server-stream.c mongoc-set.c mongoc-socket.c mongoc-ssl.c mongoc-sspi.c mongoc-stream-buffered.c mongoc-stream.c mongoc-stream-file.c mongoc-stream-gridfs.c mongoc-stream-gridfs-download.c mongoc-stream-gridfs-upload.c mongoc-stream-socket.c mongoc-stream-tls.c mongoc-stream-tls-libressl.c mongoc-stream-tls-openssl-bio.c mongoc-stream-tls-openssl.c mongoc-stream-tls-secure-channel.c mongoc-stream-tls-secure-transport.c mongoc-timeout.c mongoc-topology-background-monitoring.c mongoc-topology.c mongoc-topology-description-apm.c mongoc-topology-description.c mongoc-topology-scanner.c mongoc-uri.c mongoc-util.c mongoc-version-functions.c mongoc-write-command.c mongoc-write-command-legacy.c mongoc-write-concern.c"

dnl Generated with: find src/libmongoc/src/zlib-1.2.11 -maxdepth 1 -name '*.c' -print0 | cut -sz -d / -f 5- | sort -dz | tr '\000' ' '
PHP_MONGODB_ZLIB_SOURCES="adler32.c compress.c crc32.c deflate.c gzclose.c gzlib.c gzread.c gzwrite.c infback.c inffast.c inflate.c inftrees.c trees.c uncompr.c zutil.c"
Expand Down
2 changes: 1 addition & 1 deletion config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ if (PHP_MONGODB != "no") {
var PHP_MONGODB_JSONSL_SOURCES="jsonsl.c";

// Generated with: find src/libmongoc/src/libmongoc/src/mongoc -name '*.c' -print0 | cut -sz -d / -f 7- | sort -dz | tr '\000' ' '
var PHP_MONGODB_MONGOC_SOURCES="mongoc-aggregate.c mongoc-apm.c mongoc-array.c mongoc-async.c mongoc-async-cmd.c mongoc-buffer.c mongoc-bulk-operation.c mongoc-change-stream.c mongoc-client.c mongoc-client-pool.c mongoc-client-session.c mongoc-client-side-encryption.c mongoc-cluster-aws.c mongoc-cluster.c mongoc-cluster-cyrus.c mongoc-cluster-sasl.c mongoc-cluster-sspi.c mongoc-cmd.c mongoc-collection.c mongoc-compression.c mongoc-counters.c mongoc-crypt.c mongoc-crypto.c mongoc-crypto-cng.c mongoc-crypto-common-crypto.c mongoc-crypto-openssl.c mongoc-cursor-array.c mongoc-cursor.c mongoc-cursor-change-stream.c mongoc-cursor-cmd.c mongoc-cursor-cmd-deprecated.c mongoc-cursor-find.c mongoc-cursor-find-cmd.c mongoc-cursor-find-opquery.c mongoc-cursor-legacy.c mongoc-cyrus.c mongoc-database.c mongoc-error.c mongoc-find-and-modify.c mongoc-gridfs-bucket.c mongoc-gridfs-bucket-file.c mongoc-gridfs.c mongoc-gridfs-file.c mongoc-gridfs-file-list.c mongoc-gridfs-file-page.c mongoc-handshake.c mongoc-host-list.c mongoc-http.c mongoc-index.c mongoc-init.c mongoc-interrupt.c mongoc-libressl.c mongoc-linux-distro-scanner.c mongoc-list.c mongoc-log.c mongoc-matcher.c mongoc-matcher-op.c mongoc-memcmp.c mongoc-ocsp-cache.c mongoc-openssl.c mongoc-opts.c mongoc-opts-helpers.c mongoc-queue.c mongoc-rand-cng.c mongoc-rand-common-crypto.c mongoc-rand-openssl.c mongoc-read-concern.c mongoc-read-prefs.c mongoc-rpc.c mongoc-sasl.c mongoc-scram.c mongoc-secure-channel.c mongoc-secure-transport.c mongoc-server-api.c mongoc-server-description.c mongoc-server-monitor.c mongoc-server-stream.c mongoc-set.c mongoc-socket.c mongoc-ssl.c mongoc-sspi.c mongoc-stream-buffered.c mongoc-stream.c mongoc-stream-file.c mongoc-stream-gridfs.c mongoc-stream-gridfs-download.c mongoc-stream-gridfs-upload.c mongoc-stream-socket.c mongoc-stream-tls.c mongoc-stream-tls-libressl.c mongoc-stream-tls-openssl-bio.c mongoc-stream-tls-openssl.c mongoc-stream-tls-secure-channel.c mongoc-stream-tls-secure-transport.c mongoc-timeout.c mongoc-topology-background-monitoring.c mongoc-topology.c mongoc-topology-description-apm.c mongoc-topology-description.c mongoc-topology-scanner.c mongoc-uri.c mongoc-util.c mongoc-version-functions.c mongoc-write-command.c mongoc-write-command-legacy.c mongoc-write-concern.c";
var PHP_MONGODB_MONGOC_SOURCES="mongoc-aggregate.c mongoc-apm.c mongoc-array.c mongoc-async.c mongoc-async-cmd.c mongoc-buffer.c mongoc-bulk-operation.c mongoc-change-stream.c mongoc-client.c mongoc-client-pool.c mongoc-client-session.c mongoc-client-side-encryption.c mongoc-cluster-aws.c mongoc-cluster.c mongoc-cluster-cyrus.c mongoc-cluster-sasl.c mongoc-cluster-sspi.c mongoc-cmd.c mongoc-collection.c mongoc-compression.c mongoc-counters.c mongoc-crypt.c mongoc-crypto.c mongoc-crypto-cng.c mongoc-crypto-common-crypto.c mongoc-crypto-openssl.c mongoc-cursor-array.c mongoc-cursor.c mongoc-cursor-change-stream.c mongoc-cursor-cmd.c mongoc-cursor-cmd-deprecated.c mongoc-cursor-find.c mongoc-cursor-find-cmd.c mongoc-cursor-find-opquery.c mongoc-cursor-legacy.c mongoc-cyrus.c mongoc-database.c mongoc-error.c mongoc-find-and-modify.c mongoc-gridfs-bucket.c mongoc-gridfs-bucket-file.c mongoc-gridfs.c mongoc-gridfs-file.c mongoc-gridfs-file-list.c mongoc-gridfs-file-page.c mongoc-handshake.c mongoc-host-list.c mongoc-http.c mongoc-index.c mongoc-init.c mongoc-interrupt.c mongoc-libressl.c mongoc-linux-distro-scanner.c mongoc-list.c mongoc-log.c mongoc-matcher.c mongoc-matcher-op.c mongoc-memcmp.c mongoc-ocsp-cache.c mongoc-openssl.c mongoc-optional.c mongoc-opts.c mongoc-opts-helpers.c mongoc-queue.c mongoc-rand-cng.c mongoc-rand-common-crypto.c mongoc-rand-openssl.c mongoc-read-concern.c mongoc-read-prefs.c mongoc-rpc.c mongoc-sasl.c mongoc-scram.c mongoc-secure-channel.c mongoc-secure-transport.c mongoc-server-api.c mongoc-server-description.c mongoc-server-monitor.c mongoc-server-stream.c mongoc-set.c mongoc-socket.c mongoc-ssl.c mongoc-sspi.c mongoc-stream-buffered.c mongoc-stream.c mongoc-stream-file.c mongoc-stream-gridfs.c mongoc-stream-gridfs-download.c mongoc-stream-gridfs-upload.c mongoc-stream-socket.c mongoc-stream-tls.c mongoc-stream-tls-libressl.c mongoc-stream-tls-openssl-bio.c mongoc-stream-tls-openssl.c mongoc-stream-tls-secure-channel.c mongoc-stream-tls-secure-transport.c mongoc-timeout.c mongoc-topology-background-monitoring.c mongoc-topology.c mongoc-topology-description-apm.c mongoc-topology-description.c mongoc-topology-scanner.c mongoc-uri.c mongoc-util.c mongoc-version-functions.c mongoc-write-command.c mongoc-write-command-legacy.c mongoc-write-concern.c";

EXTENSION("mongodb", "php_phongo.c phongo_compat.c", null, PHP_MONGODB_CFLAGS);
MONGODB_ADD_SOURCES("/src", "bson.c bson-encode.c");
Expand Down
1 change: 1 addition & 0 deletions scripts/convert-bson-corpus-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ function getParamsForParseError(array $test, array $case)

switch ($test['bson_type']) {
case '0x00': // Top-level document
case '0x05': // Binary
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reminded me of DRIVERS-1552. I'll trust this is correct, since that issue hasn't been discussed since I reported it.

$code = "throws(function() {\n";
$code .= sprintf(" fromJSON(%s);\n", var_export($case['string'], true));
$code .= "}, 'MongoDB\Driver\Exception\UnexpectedValueException');";
Expand Down
2 changes: 1 addition & 1 deletion src/LIBMONGOC_VERSION_CURRENT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.18.0-20210317+git7b143c65af
1.18.0-20210326+git203e6b9e26
2 changes: 1 addition & 1 deletion src/libmongoc
Submodule libmongoc updated 171 files
21 changes: 21 additions & 0 deletions tests/bson-corpus/binary-parseError-001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Binary type: $uuid wrong type
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

DO NOT EDIT THIS FILE
--FILE--
<?php

require_once __DIR__ . '/../utils/tools.php';

throws(function() {
fromJSON('{"x" : { "$uuid" : { "data" : "73ffd264-44b3-4c69-90e8-e7d1dfc035d4"}}}');
}, 'MongoDB\Driver\Exception\UnexpectedValueException');

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
===DONE===
21 changes: 21 additions & 0 deletions tests/bson-corpus/binary-parseError-002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Binary type: $uuid invalid value--too short
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

DO NOT EDIT THIS FILE
--FILE--
<?php

require_once __DIR__ . '/../utils/tools.php';

throws(function() {
fromJSON('{"x" : { "$uuid" : "73ffd264-44b3-90e8-e7d1dfc035d4"}}');
}, 'MongoDB\Driver\Exception\UnexpectedValueException');

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
===DONE===
21 changes: 21 additions & 0 deletions tests/bson-corpus/binary-parseError-003.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Binary type: $uuid invalid value--too long
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

DO NOT EDIT THIS FILE
--FILE--
<?php

require_once __DIR__ . '/../utils/tools.php';

throws(function() {
fromJSON('{"x" : { "$uuid" : "73ffd264-44b3-4c69-90e8-e7d1dfc035d4-789e4"}}');
}, 'MongoDB\Driver\Exception\UnexpectedValueException');

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
===DONE===
21 changes: 21 additions & 0 deletions tests/bson-corpus/binary-parseError-004.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Binary type: $uuid invalid value--misplaced hyphens
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

DO NOT EDIT THIS FILE
--FILE--
<?php

require_once __DIR__ . '/../utils/tools.php';

throws(function() {
fromJSON('{"x" : { "$uuid" : "73ff-d26444b-34c6-990e8e-7d1dfc035d4"}}');
}, 'MongoDB\Driver\Exception\UnexpectedValueException');

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
===DONE===
21 changes: 21 additions & 0 deletions tests/bson-corpus/binary-parseError-005.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Binary type: $uuid invalid value--too many hyphens
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

DO NOT EDIT THIS FILE
--FILE--
<?php

require_once __DIR__ . '/../utils/tools.php';

throws(function() {
fromJSON('{"x" : { "$uuid" : "----d264-44b3-4--9-90e8-e7d1dfc0----"}}');
}, 'MongoDB\Driver\Exception\UnexpectedValueException');

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
===DONE===
17 changes: 11 additions & 6 deletions tests/bson-corpus/binary-valid-008.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Binary type: subtype 0x05
Binary type: subtype 0x04 UUID
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

Expand All @@ -9,8 +9,9 @@ DO NOT EDIT THIS FILE

require_once __DIR__ . '/../utils/tools.php';

$canonicalBson = hex2bin('1D000000057800100000000573FFD26444B34C6990E8E7D1DFC035D400');
$canonicalExtJson = '{"x" : { "$binary" : {"base64" : "c//SZESzTGmQ6OfR38A11A==", "subType" : "05"}}}';
$canonicalBson = hex2bin('1D000000057800100000000473FFD26444B34C6990E8E7D1DFC035D400');
$canonicalExtJson = '{"x" : { "$binary" : {"base64" : "c//SZESzTGmQ6OfR38A11A==", "subType" : "04"}}}';
$degenerateExtJson = '{"x" : { "$uuid" : "73ffd264-44b3-4c69-90e8-e7d1dfc035d4"}}';

// Canonical BSON -> Native -> Canonical BSON
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";
Expand All @@ -21,11 +22,15 @@ echo json_canonicalize(toCanonicalExtendedJSON($canonicalBson)), "\n";
// Canonical extJSON -> Canonical BSON
echo bin2hex(fromJSON($canonicalExtJson)), "\n";

// Degenerate extJSON -> Canonical BSON
echo bin2hex(fromJSON($degenerateExtJson)), "\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
1d000000057800100000000573ffd26444b34c6990e8e7d1dfc035d400
{"x":{"$binary":{"base64":"c\/\/SZESzTGmQ6OfR38A11A==","subType":"05"}}}
1d000000057800100000000573ffd26444b34c6990e8e7d1dfc035d400
1d000000057800100000000473ffd26444b34c6990e8e7d1dfc035d400
{"x":{"$binary":{"base64":"c\/\/SZESzTGmQ6OfR38A11A==","subType":"04"}}}
1d000000057800100000000473ffd26444b34c6990e8e7d1dfc035d400
1d000000057800100000000473ffd26444b34c6990e8e7d1dfc035d400
===DONE===
12 changes: 6 additions & 6 deletions tests/bson-corpus/binary-valid-009.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Binary type: subtype 0x80
Binary type: subtype 0x05
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

Expand All @@ -9,8 +9,8 @@ DO NOT EDIT THIS FILE

require_once __DIR__ . '/../utils/tools.php';

$canonicalBson = hex2bin('0F0000000578000200000080FFFF00');
$canonicalExtJson = '{"x" : { "$binary" : {"base64" : "//8=", "subType" : "80"}}}';
$canonicalBson = hex2bin('1D000000057800100000000573FFD26444B34C6990E8E7D1DFC035D400');
$canonicalExtJson = '{"x" : { "$binary" : {"base64" : "c//SZESzTGmQ6OfR38A11A==", "subType" : "05"}}}';

// Canonical BSON -> Native -> Canonical BSON
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";
Expand All @@ -25,7 +25,7 @@ echo bin2hex(fromJSON($canonicalExtJson)), "\n";
===DONE===
<?php exit(0); ?>
--EXPECT--
0f0000000578000200000080ffff00
{"x":{"$binary":{"base64":"\/\/8=","subType":"80"}}}
0f0000000578000200000080ffff00
1d000000057800100000000573ffd26444b34c6990e8e7d1dfc035d400
{"x":{"$binary":{"base64":"c\/\/SZESzTGmQ6OfR38A11A==","subType":"05"}}}
1d000000057800100000000573ffd26444b34c6990e8e7d1dfc035d400
===DONE===
12 changes: 6 additions & 6 deletions tests/bson-corpus/binary-valid-010.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Binary type: $type query operator (conflicts with legacy $binary form with $type field)
Binary type: subtype 0x80
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

Expand All @@ -9,8 +9,8 @@ DO NOT EDIT THIS FILE

require_once __DIR__ . '/../utils/tools.php';

$canonicalBson = hex2bin('1F000000037800170000000224747970650007000000737472696E67000000');
$canonicalExtJson = '{"x" : { "$type" : "string"}}';
$canonicalBson = hex2bin('0F0000000578000200000080FFFF00');
$canonicalExtJson = '{"x" : { "$binary" : {"base64" : "//8=", "subType" : "80"}}}';

// Canonical BSON -> Native -> Canonical BSON
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";
Expand All @@ -25,7 +25,7 @@ echo bin2hex(fromJSON($canonicalExtJson)), "\n";
===DONE===
<?php exit(0); ?>
--EXPECT--
1f000000037800170000000224747970650007000000737472696e67000000
{"x":{"$type":"string"}}
1f000000037800170000000224747970650007000000737472696e67000000
0f0000000578000200000080ffff00
{"x":{"$binary":{"base64":"\/\/8=","subType":"80"}}}
0f0000000578000200000080ffff00
===DONE===
10 changes: 5 additions & 5 deletions tests/bson-corpus/binary-valid-011.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ DO NOT EDIT THIS FILE

require_once __DIR__ . '/../utils/tools.php';

$canonicalBson = hex2bin('180000000378001000000010247479706500020000000000');
$canonicalExtJson = '{"x" : { "$type" : {"$numberInt": "2"}}}';
$canonicalBson = hex2bin('1F000000037800170000000224747970650007000000737472696E67000000');
$canonicalExtJson = '{"x" : { "$type" : "string"}}';

// Canonical BSON -> Native -> Canonical BSON
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";
Expand All @@ -25,7 +25,7 @@ echo bin2hex(fromJSON($canonicalExtJson)), "\n";
===DONE===
<?php exit(0); ?>
--EXPECT--
180000000378001000000010247479706500020000000000
{"x":{"$type":{"$numberInt":"2"}}}
180000000378001000000010247479706500020000000000
1f000000037800170000000224747970650007000000737472696e67000000
{"x":{"$type":"string"}}
1f000000037800170000000224747970650007000000737472696e67000000
===DONE===
31 changes: 31 additions & 0 deletions tests/bson-corpus/binary-valid-012.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
Binary type: $type query operator (conflicts with legacy $binary form with $type field)
--DESCRIPTION--
Generated by scripts/convert-bson-corpus-tests.php

DO NOT EDIT THIS FILE
--FILE--
<?php

require_once __DIR__ . '/../utils/tools.php';

$canonicalBson = hex2bin('180000000378001000000010247479706500020000000000');
$canonicalExtJson = '{"x" : { "$type" : {"$numberInt": "2"}}}';

// Canonical BSON -> Native -> Canonical BSON
echo bin2hex(fromPHP(toPHP($canonicalBson))), "\n";

// Canonical BSON -> Canonical extJSON
echo json_canonicalize(toCanonicalExtendedJSON($canonicalBson)), "\n";

// Canonical extJSON -> Canonical BSON
echo bin2hex(fromJSON($canonicalExtJson)), "\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
180000000378001000000010247479706500020000000000
{"x":{"$type":{"$numberInt":"2"}}}
180000000378001000000010247479706500020000000000
===DONE===