Skip to content

Commit 20bbaf3

Browse files
committed
Changed to ignore fields with unsupported types, and upgraded test cases.
1 parent 1252a6e commit 20bbaf3

File tree

3 files changed

+13
-69
lines changed

3 files changed

+13
-69
lines changed

src/bson.c

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,8 @@ static bool php_phongo_bson_visit_binary(const bson_iter_t *iter ARG_UNUSED, con
131131

132132
static bool php_phongo_bson_visit_undefined(const bson_iter_t *iter, const char *key, void *data) /* {{{ */
133133
{
134-
zval *retval = PHONGO_BSON_STATE_ZCHILD(data);
135-
136134
mongoc_log(MONGOC_LOG_LEVEL_WARNING, MONGOC_LOG_DOMAIN, "Detected unsupported BSON type 0x06 (undefined) for fieldname \"%s\"", key);
137135

138-
if (((php_phongo_bson_state *)data)->is_visiting_array) {
139-
add_next_index_null(retval);
140-
} else {
141-
add_assoc_null(retval, key);
142-
}
143-
144136
return false;
145137
} /* }}} */
146138

@@ -292,16 +284,8 @@ static bool php_phongo_bson_visit_regex(const bson_iter_t *iter ARG_UNUSED, cons
292284

293285
static bool php_phongo_bson_visit_symbol(const bson_iter_t *iter, const char *key, size_t symbol_len, const char *symbol, void *data) /* {{{ */
294286
{
295-
zval *retval = PHONGO_BSON_STATE_ZCHILD(data);
296-
297287
mongoc_log(MONGOC_LOG_LEVEL_WARNING, MONGOC_LOG_DOMAIN, "Detected unsupported BSON type 0x0E (symbol) for fieldname \"%s\"", key);
298288

299-
if (((php_phongo_bson_state *)data)->is_visiting_array) {
300-
add_next_index_null(retval);
301-
} else {
302-
add_assoc_null(retval, key);
303-
}
304-
305289
return false;
306290
} /* }}} */
307291

@@ -337,16 +321,8 @@ static bool php_phongo_bson_visit_code(const bson_iter_t *iter ARG_UNUSED, const
337321

338322
static bool php_phongo_bson_visit_dbpointer(const bson_iter_t *iter, const char *key, size_t collection_len, const char *collection, const bson_oid_t *oid, void *data) /* {{{ */
339323
{
340-
zval *retval = PHONGO_BSON_STATE_ZCHILD(data);
341-
342324
mongoc_log(MONGOC_LOG_LEVEL_WARNING, MONGOC_LOG_DOMAIN, "Detected unsupported BSON type 0x0C (DBPointer) for fieldname \"%s\"", key);
343325

344-
if (((php_phongo_bson_state *)data)->is_visiting_array) {
345-
add_next_index_null(retval);
346-
} else {
347-
add_assoc_null(retval, key);
348-
}
349-
350326
return false;
351327
} /* }}} */
352328

tests/bson/bson-toPHP_error-005.phpt

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,30 @@
11
--TEST--
2-
MongoDB\BSON\toPHP(): BSON decoding exceptions for unsupported BSON types
2+
MongoDB\BSON\toPHP(): BSON decoding ignores unsupported BSON types
33
--FILE--
44
<?php
5-
6-
require_once __DIR__ . '/../utils/tools.php';
7-
85
$tests = [
96
pack('VCa*xx', 10, 0x06, 'foo'), // undefined
107
pack('VCa*xVa*xx12x', 37, 0x0C, 'foo', 11, 'collection'), // DBPointer
118
pack('VCa*xVa*xx', 18, 0x0E, 'foo', 4, 'bar'), // symbol
129
];
1310

14-
ini_set("mongodb.debug", "stdout");
11+
ini_set('mongodb.debug', 'stdout');
1512
foreach ($tests as $bson) {
16-
var_dump(toPHP($bson));
13+
var_dump(MongoDB\BSON\toPHP($bson));
1714
}
18-
ini_set("mongodb.debug", "off");
15+
ini_set('mongodb.debug', 'off');
1916

2017
?>
2118
===DONE===
2219
<?php exit(0); ?>
2320
--EXPECTF--
2421
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x06 (undefined) for fieldname "foo"
2522
object(stdClass)#%d (%d) {
26-
["foo"]=>
27-
NULL
2823
}
2924
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x0C (DBPointer) for fieldname "foo"
3025
object(stdClass)#%d (%d) {
31-
["foo"]=>
32-
NULL
3326
}
3427
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x0E (symbol) for fieldname "foo"
3528
object(stdClass)#%d (%d) {
36-
["foo"]=>
37-
NULL
3829
}
3930
===DONE===

tests/bson/bson-toPHP_error-006.phpt

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
--TEST--
2-
MongoDB\BSON\toPHP(): BSON decoding throws multiple exceptions
2+
MongoDB\BSON\toPHP(): BSON decoding shows multiple warnings
33
--FILE--
44
<?php
55

6-
require_once __DIR__ . '/../utils/tools.php';
7-
86
$tests = [
97
// two undefined fields in root document
108
pack('VCa*xCa*xx', 13, 0x06, 'u1', 0x06, 'u2'),
@@ -18,66 +16,45 @@ $tests = [
1816
pack('VCa*xVCa*xxCa*xVCa*xxx', 31, 0x03, 'e1', 9, 0x06, 'u1', 0x03, 'e2', 9, 0x06, 'u2'),
1917
];
2018

21-
ini_set("mongodb.debug", "stdout");
19+
ini_set('mongodb.debug', 'stdout');
2220
foreach ($tests as $bson) {
23-
var_dump(toPHP($bson));
21+
var_dump(MongoDB\BSON\toPHP($bson));
2422
}
25-
ini_set("mongodb.debug", "off");
26-
23+
ini_set('mongodb.debug', 'off');
2724
?>
2825
===DONE===
2926
<?php exit(0); ?>
3027
--EXPECTF--
3128
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x06 (undefined) for fieldname "u1"
3229
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x06 (undefined) for fieldname "u2"
3330
object(stdClass)#%d (%d) {
34-
["u1"]=>
35-
NULL
36-
["u2"]=>
37-
NULL
3831
}
3932
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x06 (undefined) for fieldname "u1"
4033
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x0E (symbol) for fieldname "s1"
4134
object(stdClass)#%d (%d) {
42-
["u1"]=>
43-
NULL
44-
["s1"]=>
45-
NULL
4635
}
4736
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x06 (undefined) for fieldname "u1"
4837
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x06 (undefined) for fieldname "u2"
4938
object(stdClass)#%d (%d) {
50-
["u1"]=>
51-
NULL
5239
["e1"]=>
53-
object(stdClass)#%d (%d) {
54-
["u2"]=>
55-
NULL
40+
object(stdClass)#%d (0) {
5641
}
5742
}
5843
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x06 (undefined) for fieldname "u1"
5944
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x06 (undefined) for fieldname "u2"
6045
object(stdClass)#%d (%d) {
6146
["e1"]=>
62-
object(stdClass)#%d (%d) {
63-
["u1"]=>
64-
NULL
47+
object(stdClass)#%d (0) {
6548
}
66-
["u2"]=>
67-
NULL
6849
}
6950
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x06 (undefined) for fieldname "u1"
7051
[%s] PHONGO-BSON: WARNING > Detected unsupported BSON type 0x06 (undefined) for fieldname "u2"
71-
object(stdClass)#3 (%d) {
52+
object(stdClass)#%d (%d) {
7253
["e1"]=>
73-
object(stdClass)#%d (%d) {
74-
["u1"]=>
75-
NULL
54+
object(stdClass)#%d (0) {
7655
}
7756
["e2"]=>
78-
object(stdClass)#%d (%d) {
79-
["u2"]=>
80-
NULL
57+
object(stdClass)#%d (0) {
8158
}
8259
}
8360
===DONE===

0 commit comments

Comments
 (0)