summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorGabriel Russell <gabriel.russell@mongodb.com>2019-10-15 19:53:38 +0000
committerevergreen <evergreen@mongodb.com>2019-10-15 19:53:38 +0000
commita6e3d841fcb4bc219ad56e3defc898ae18de9dbd (patch)
tree72b95d223bcd4328238a4520b233f9b7b5ffe8e5 /src/mongo
parent380711ea7dba41cb372a12a8d5258fdc124a0d23 (diff)
downloadmongo-a6e3d841fcb4bc219ad56e3defc898ae18de9dbd.tar.gz
Revert "SERVER-41994 correctly create and show type 2 binary elements"
This reverts commit 3f6ba750fc8374968c3c06e31c67ac2839e9a736.
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/bson/bsonelement.cpp6
-rw-r--r--src/mongo/bson/bsonelement.h15
-rw-r--r--src/mongo/bson/bsonelement_test.cpp15
-rw-r--r--src/mongo/bson/bsonobjbuilder.h7
-rw-r--r--src/mongo/scripting/mozjs/valuereader.cpp2
5 files changed, 7 insertions, 38 deletions
diff --git a/src/mongo/bson/bsonelement.cpp b/src/mongo/bson/bsonelement.cpp
index 940589d193b..c72e61eb888 100644
--- a/src/mongo/bson/bsonelement.cpp
+++ b/src/mongo/bson/bsonelement.cpp
@@ -213,11 +213,7 @@ void BSONElement::jsonStringStream(JsonStringFormat format,
BinDataType type = static_cast<BinDataType>(reader.readAndAdvance<uint8_t>());
s << "{ \"$binary\" : \"";
- if (type == ByteArrayDeprecated && len >= 4) {
- base64::encode(s, reader.view() + 4, len - 4);
- } else {
- base64::encode(s, reader.view(), len);
- }
+ base64::encode(s, reader.view(), len);
auto origFill = s.fill();
auto origFmtF = s.flags();
diff --git a/src/mongo/bson/bsonelement.h b/src/mongo/bson/bsonelement.h
index d7733b7966a..892be6df831 100644
--- a/src/mongo/bson/bsonelement.h
+++ b/src/mongo/bson/bsonelement.h
@@ -494,18 +494,9 @@ public:
if (binDataType() != ByteArrayDeprecated) {
return binData(len);
} else {
- // Because, for some time, the shell has incorrectly created type 2 binary objects
- // without the extra length, we try to identify if this object does or doesn't start
- // with a length and skip past it when its present. See SERVER-41994
- if (valuestrsize() >= 4 &&
- ConstDataView(value() + 5).read<LittleEndian<int>>() == valuestrsize() - 4) {
- // Skip extra size
- len = valuestrsize() - 4;
- return value() + 5 + 4;
- } else {
- len = valuestrsize();
- return value() + 5;
- }
+ // Skip extra size
+ len = valuestrsize() - 4;
+ return value() + 5 + 4;
}
}
diff --git a/src/mongo/bson/bsonelement_test.cpp b/src/mongo/bson/bsonelement_test.cpp
index b3f6725425f..f98ccf93894 100644
--- a/src/mongo/bson/bsonelement_test.cpp
+++ b/src/mongo/bson/bsonelement_test.cpp
@@ -72,19 +72,6 @@ TEST(BSONElement, BinDataToString) {
builder.appendBinData(
"unknownType", unknownType.size(), unknownBinDataType, unknownType.rawData());
- builder.bb().appendNum((char)BinData);
- builder.bb().appendStr("brokenType2");
- builder.bb().appendNum(3);
- builder.bb().appendNum((char)ByteArrayDeprecated);
- builder.bb().appendBuf("foo", 3);
-
- builder.bb().appendNum((char)BinData);
- builder.bb().appendStr("fixedType2");
- builder.bb().appendNum(4 + 3);
- builder.bb().appendNum((char)ByteArrayDeprecated);
- builder.bb().appendNum(3);
- builder.bb().appendBuf("foo", 3);
-
BSONObj obj = builder.obj();
ASSERT_EQ(obj["bintype0"].toString(), "bintype0: BinData(0, DEEABEEF01)");
ASSERT_EQ(obj["validUUID"].toString(), "validUUID: UUID(\"" + validUUID.toString() + "\")");
@@ -96,8 +83,6 @@ TEST(BSONElement, BinDataToString) {
ASSERT_EQ(obj["unknownType"].toString(),
"unknownType: BinData(42, "
"62696E6172792064617461007769746820616E20756E6B6E6F776E2074797065)");
- ASSERT_EQ(obj["brokenType2"].toString(), "brokenType2: BinData(2, 666F6F)");
- ASSERT_EQ(obj["fixedType2"].toString(), "fixedType2: BinData(2, 666F6F)");
}
diff --git a/src/mongo/bson/bsonobjbuilder.h b/src/mongo/bson/bsonobjbuilder.h
index e520482539e..de68ff65353 100644
--- a/src/mongo/bson/bsonobjbuilder.h
+++ b/src/mongo/bson/bsonobjbuilder.h
@@ -513,9 +513,6 @@ public:
int len,
BinDataType type,
const void* data) {
- if (type == ByteArrayDeprecated) {
- return appendBinDataArrayDeprecated(fieldName, data, len);
- }
_b.appendNum((char)BinData);
_b.appendStr(fieldName);
_b.appendNum(len);
@@ -534,11 +531,11 @@ public:
@param data a byte array
@param len the length of data
*/
- BSONObjBuilder& appendBinDataArrayDeprecated(StringData fieldName, const void* data, int len) {
+ BSONObjBuilder& appendBinDataArrayDeprecated(const char* fieldName, const void* data, int len) {
_b.appendNum((char)BinData);
_b.appendStr(fieldName);
_b.appendNum(len + 4);
- _b.appendNum((char)ByteArrayDeprecated);
+ _b.appendNum((char)0x2);
_b.appendNum(len);
_b.appendBuf(data, len);
return *this;
diff --git a/src/mongo/scripting/mozjs/valuereader.cpp b/src/mongo/scripting/mozjs/valuereader.cpp
index e518cec2e7e..66a48ddd707 100644
--- a/src/mongo/scripting/mozjs/valuereader.cpp
+++ b/src/mongo/scripting/mozjs/valuereader.cpp
@@ -136,7 +136,7 @@ void ValueReader::fromBSONElement(const BSONElement& elem, const BSONObj& parent
}
case mongo::BinData: {
int len;
- const char* data = elem.binDataClean(len);
+ const char* data = elem.binData(len);
std::stringstream ss;
base64::encode(ss, data, len);