1818#include < bsoncxx/builder/basic/sub_array.hpp>
1919#include < bsoncxx/exception/exception.hpp>
2020#include < bsoncxx/json.hpp>
21+ #include < bsoncxx/private/libbson.hh>
2122#include < bsoncxx/test_util/catch.hh>
2223
2324namespace {
@@ -97,9 +98,18 @@ TEST_CASE("CXX-1246: Relaxed Extended JSON") {
9798 binary_sub_type::k_uuid, 8 , reinterpret_cast <const uint8_t *>(" deadbeef" )};
9899 auto doc = make_document (kvp (" number" , 42 ), kvp (" bin" , bin_val));
99100 auto output = to_json (doc.view (), ExtendedJsonMode::k_relaxed);
100- REQUIRE (
101- output ==
102- R"( { "number" : 42, "bin" : { "$binary" : { "base64": "ZGVhZGJlZWY=", "subType" : "04" } } })" );
101+
102+ // As of libbson 1.18.0, "base64" has correct spacing (see CDRIVER-3958) after extJSON
103+ // marshalling.
104+ const char * expected;
105+ if ((BSON_MAJOR_VERSION == 1 && BSON_MINOR_VERSION >= 18 ) || BSON_MAJOR_VERSION > 1 ) {
106+ expected =
107+ R"( { "number" : 42, "bin" : { "$binary" : { "base64" : "ZGVhZGJlZWY=", "subType" : "04" } } })" ;
108+ } else {
109+ expected =
110+ R"( { "number" : 42, "bin" : { "$binary" : { "base64": "ZGVhZGJlZWY=", "subType" : "04" } } })" ;
111+ }
112+ REQUIRE (output == expected);
103113}
104114
105115TEST_CASE (" CXX-1246: Canonical Extended JSON" ) {
@@ -108,8 +118,17 @@ TEST_CASE("CXX-1246: Canonical Extended JSON") {
108118 binary_sub_type::k_uuid, 8 , reinterpret_cast <const uint8_t *>(" deadbeef" )};
109119 auto doc = make_document (kvp (" number" , 42 ), kvp (" bin" , bin_val));
110120 auto output = to_json (doc.view (), ExtendedJsonMode::k_canonical);
111- REQUIRE (
112- output ==
113- R"( { "number" : { "$numberInt" : "42" }, "bin" : { "$binary" : { "base64": "ZGVhZGJlZWY=", "subType" : "04" } } })" );
121+
122+ // As of libbson 1.18.0, "base64" has correct spacing (see CDRIVER-3958) after extJSON
123+ // marshalling.
124+ const char * expected;
125+ if ((BSON_MAJOR_VERSION == 1 && BSON_MINOR_VERSION >= 18 ) || BSON_MAJOR_VERSION > 1 ) {
126+ expected =
127+ R"( { "number" : { "$numberInt" : "42" }, "bin" : { "$binary" : { "base64" : "ZGVhZGJlZWY=", "subType" : "04" } } })" ;
128+ } else {
129+ expected =
130+ R"( { "number" : { "$numberInt" : "42" }, "bin" : { "$binary" : { "base64": "ZGVhZGJlZWY=", "subType" : "04" } } })" ;
131+ }
132+ REQUIRE (output == expected);
114133}
115134} // namespace
0 commit comments