From 60e3bcde353131249b202b03be44def949b806f2 Mon Sep 17 00:00:00 2001 From: Benjamin Rewis Date: Tue, 4 May 2021 13:42:29 -0400 Subject: [PATCH] CXX-2234 Expect space after base64 in extJSON binary --- src/bsoncxx/test/json.cpp | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/bsoncxx/test/json.cpp b/src/bsoncxx/test/json.cpp index ad34dbda98..67d68a7786 100644 --- a/src/bsoncxx/test/json.cpp +++ b/src/bsoncxx/test/json.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include namespace { @@ -97,9 +98,18 @@ TEST_CASE("CXX-1246: Relaxed Extended JSON") { binary_sub_type::k_uuid, 8, reinterpret_cast("deadbeef")}; auto doc = make_document(kvp("number", 42), kvp("bin", bin_val)); auto output = to_json(doc.view(), ExtendedJsonMode::k_relaxed); - REQUIRE( - output == - R"({ "number" : 42, "bin" : { "$binary" : { "base64": "ZGVhZGJlZWY=", "subType" : "04" } } })"); + + // As of libbson 1.18.0, "base64" has correct spacing (see CDRIVER-3958) after extJSON + // marshalling. + const char* expected; + if ((BSON_MAJOR_VERSION == 1 && BSON_MINOR_VERSION >= 18) || BSON_MAJOR_VERSION > 1) { + expected = + R"({ "number" : 42, "bin" : { "$binary" : { "base64" : "ZGVhZGJlZWY=", "subType" : "04" } } })"; + } else { + expected = + R"({ "number" : 42, "bin" : { "$binary" : { "base64": "ZGVhZGJlZWY=", "subType" : "04" } } })"; + } + REQUIRE(output == expected); } TEST_CASE("CXX-1246: Canonical Extended JSON") { @@ -108,8 +118,17 @@ TEST_CASE("CXX-1246: Canonical Extended JSON") { binary_sub_type::k_uuid, 8, reinterpret_cast("deadbeef")}; auto doc = make_document(kvp("number", 42), kvp("bin", bin_val)); auto output = to_json(doc.view(), ExtendedJsonMode::k_canonical); - REQUIRE( - output == - R"({ "number" : { "$numberInt" : "42" }, "bin" : { "$binary" : { "base64": "ZGVhZGJlZWY=", "subType" : "04" } } })"); + + // As of libbson 1.18.0, "base64" has correct spacing (see CDRIVER-3958) after extJSON + // marshalling. + const char* expected; + if ((BSON_MAJOR_VERSION == 1 && BSON_MINOR_VERSION >= 18) || BSON_MAJOR_VERSION > 1) { + expected = + R"({ "number" : { "$numberInt" : "42" }, "bin" : { "$binary" : { "base64" : "ZGVhZGJlZWY=", "subType" : "04" } } })"; + } else { + expected = + R"({ "number" : { "$numberInt" : "42" }, "bin" : { "$binary" : { "base64": "ZGVhZGJlZWY=", "subType" : "04" } } })"; + } + REQUIRE(output == expected); } } // namespace