Skip to content

Commit 9e6e351

Browse files
authored
CXX-2234 Expect space after base64 in extJSON binary (#791)
1 parent 4f82a99 commit 9e6e351

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/bsoncxx/test/json.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
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

2324
namespace {
@@ -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

105115
TEST_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

Comments
 (0)