|
The spec for code_with_scope says that the javascript is a "string", which is allowed to have embedded nulls. However the API for bson_append_code_with_scope has no parameter for the javascript length, so computes it with strlen in bson.c line 963. This truncates any input with embedded nulls.
In order to fully support the spec and pass the BSON Corpus tests, we need a new function:
|
/**
|
* bson_append_code_with_scope_and_length:
|
* @bson: A bson_t.
|
* @key: The key for the document.
|
* @javascript: JavaScript code to be executed.
|
* @scope: A bson_t containing the scope for @javascript.
|
*
|
* Appends a field of type BSON_TYPE_CODE to the BSON document
|
* if @scope is NULL. Appends BSON_TYPE_CODEWSCOPE if @scope
|
* is not NULL (even if it is an empty document). Unlike
|
* bson_append_code_with_scope, this function makes it possible
|
* to embed literal NULL bytes in the Javascript text.
|
*
|
* Returns: true if successful; false if append would overflow max size.
|
*/
|
BSON_API
|
bool
|
bson_append_code_with_scope_and_length (bson_t *bson,
|
const char *key,
|
int key_length,
|
const char *javascript,
|
int js_length,
|
const bson_t *scope);
|
|