Skip to content

Commit d616162

Browse files
committed
PHPC-1001: Report field name for invalid UTF-8 and unsupported zval types
1 parent 7f71683 commit d616162

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

src/bson-encode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ static void php_phongo_bson_append(bson_t *bson, php_phongo_bson_flags_t flags,
321321
if (bson_utf8_validate(Z_STRVAL_P(entry), Z_STRLEN_P(entry), true)) {
322322
bson_append_utf8(bson, key, key_len, Z_STRVAL_P(entry), Z_STRLEN_P(entry));
323323
} else {
324-
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "Got invalid UTF-8 value serializing '%s'", Z_STRVAL_P(entry));
324+
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "Detected invalid UTF-8 for fieldname \"%s\": %s", key, Z_STRVAL_P(entry));
325325
}
326326
break;
327327

@@ -380,7 +380,7 @@ static void php_phongo_bson_append(bson_t *bson, php_phongo_bson_flags_t flags,
380380
#endif
381381

382382
default:
383-
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "Got unsupported type %d '%s'", Z_TYPE_P(entry), zend_get_type_by_const(Z_TYPE_P(entry)));
383+
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC, "Detected unsupported PHP type for fieldname \"%s\": %d (%s)", key, Z_TYPE_P(entry), zend_get_type_by_const(Z_TYPE_P(entry)));
384384
}
385385
} /* }}} */
386386

tests/bulk/bulkwrite-delete_error-002.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ echo throws(function() use ($bulk) {
2020
<?php exit(0); ?>
2121
--EXPECTF--
2222
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
23-
Got invalid UTF-8 value serializing '%s'
23+
Detected invalid UTF-8 for fieldname "x": %s
2424

2525
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
26-
Got invalid UTF-8 value serializing '%s'
26+
Detected invalid UTF-8 for fieldname "locale": %s
2727
===DONE===

tests/bulk/bulkwrite-insert_error-002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ echo throws(function() use ($bulk) {
1616
<?php exit(0); ?>
1717
--EXPECTF--
1818
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
19-
Got invalid UTF-8 value serializing '%s'
19+
Detected invalid UTF-8 for fieldname "x": %s
2020
===DONE===

tests/bulk/bulkwrite-update_error-004.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ echo throws(function() use ($bulk) {
2828
<?php exit(0); ?>
2929
--EXPECTF--
3030
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
31-
Got invalid UTF-8 value serializing '%s'
31+
Detected invalid UTF-8 for fieldname "x": %s
3232

3333
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
34-
Got invalid UTF-8 value serializing '%s'
34+
Detected invalid UTF-8 for fieldname "x": %s
3535

3636
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
37-
Got invalid UTF-8 value serializing '%s'
37+
Detected invalid UTF-8 for fieldname "x": %s
3838

3939
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
40-
Got invalid UTF-8 value serializing '%s'
40+
Detected invalid UTF-8 for fieldname "locale": %s
4141
===DONE===

0 commit comments

Comments
 (0)