[CXX-1246] bsoncxx::builder::stream::single_context should not permit appending of multiple values Created: 07/Mar/17  Updated: 16/Mar/17  Resolved: 16/Mar/17

Status: Closed
Project: C++ Driver
Component/s: API, BSON
Affects Version/s: None
Fix Version/s: 3.2.0-rc0

Type: Bug Priority: Major - P3
Reporter: J Rassi Assignee: J Rassi
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

bsoncxx::builder::stream::single_context is written to accept a single value to be appended to the stream, but it is currently possible to append multiple values through use of open_document and open_array:

using namespace bsoncxx::builder::stream;
auto doc = document{} << "x" << [](single_context s) {
    s << open_array << 0 << close_array << open_array << 1 << close_array;
} << finalize;

The above code currently compiles, and throws an exception with a confusing message "expected a key but found none" at runtime. Instead, this code should not compile.

The code erroneously compiles due to the fact that the following functions have the wrong return type. The return type of these functions are currently key_context<single_context> and array_context<single_context>, respectively, but they should be key_context<closed_context> and array_context<closed_context> instead.

  • bsoncxx::builder::stream::single_context::operator<<(open_document_type)
  • bsoncxx::builder::stream::single_context::operator<<(open_array_type)


 Comments   
Comment by Githook User [ 16/Mar/17 ]

Author:

{u'username': u'jrassi', u'name': u'J. Rassi', u'email': u'rassi@10gen.com'}

Message: CXX-1246 single_context shouldn't permit appending of multiple values
Branch: master
https://github.com/mongodb/mongo-cxx-driver/commit/8b2a1d3a6993372040d9f9e781ac386137cbbf6e

Comment by J Rassi [ 09/Mar/17 ]

Per discussion with david.golden, putting this into 3.2.0-rc0. Note that the fix for this issue involves an API change.

Generated at Wed Feb 07 22:01:55 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.