Skip to content

Commit bd757bb

Browse files
authored
PHPC-1342: Regression tests for duplicate keys (#1294)
1 parent c2410ab commit bd757bb

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

tests/bson/bson-fromJSON-003.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
MongoDB\BSON\fromJSON(): Decoding JSON with duplicate field names
3+
--FILE--
4+
<?php
5+
6+
require_once __DIR__ . '/../utils/basic.inc';
7+
8+
/* Note: this is a regression test for libmongoc's JSON encoder. It is not
9+
* advisable to use duplicate keys in BSON documents. */
10+
hex_dump(fromJSON('{ "foo": "bar", "foo": "baz" }'));
11+
12+
?>
13+
===DONE===
14+
<?php exit(0); ?>
15+
--EXPECT--
16+
0 : 1f 00 00 00 02 66 6f 6f 00 04 00 00 00 62 61 72 [.....foo.....bar]
17+
10 : 00 02 66 6f 6f 00 04 00 00 00 62 61 7a 00 00 [..foo.....baz..]
18+
===DONE===

tests/bson/bson-toJSON-003.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
MongoDB\BSON\toJSON(): Encoding JSON with duplicate field names
3+
--FILE--
4+
<?php
5+
6+
require_once __DIR__ . '/../utils/basic.inc';
7+
8+
/* Note: this is a regression test for libmongoc's JSON encoder. It is not
9+
* advisable to use duplicate keys in BSON documents. */
10+
echo toJSON(fromJSON('{ "foo": "bar", "foo": "baz" }')), "\n";
11+
12+
?>
13+
===DONE===
14+
<?php exit(0); ?>
15+
--EXPECT--
16+
{ "foo" : "bar", "foo" : "baz" }
17+
===DONE===

tests/bson/bson-toPHP-012.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
MongoDB\BSON\toPHP(): Decoding BSON with duplicate field names
3+
--FILE--
4+
<?php
5+
6+
require_once __DIR__ . '/../utils/basic.inc';
7+
8+
/* Note: this is a regression test. It is not advisable to use duplicate keys in
9+
* BSON documents. */
10+
var_dump(toPHP(fromJSON('{ "foo": "bar", "foo": "baz" }')));
11+
12+
?>
13+
===DONE===
14+
<?php exit(0); ?>
15+
--EXPECTF--
16+
object(stdClass)#%d (%d) {
17+
["foo"]=>
18+
string(3) "baz"
19+
}
20+
===DONE===

0 commit comments

Comments
 (0)