Skip to content

Commit 3146eab

Browse files
committed
JAVA-2360: Format binary subtype as a two-digit padded hexadecimal string
1 parent 98e8b3e commit 3146eab

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

bson/src/main/org/bson/json/JsonWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ protected void doWriteBinaryData(final BsonBinary binary) {
154154
default:
155155
writeStartDocument();
156156
writeString("$binary", printBase64Binary(binary.getData()));
157-
writeString("$type", Integer.toHexString(binary.getType() & 0xFF));
157+
writeString("$type", String.format("%02X", binary.getType()));
158158
writeEndDocument();
159159
}
160160
} catch (IOException e) {

bson/src/test/unit/org/bson/json/JsonWriterTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,16 +409,16 @@ public void testArray() {
409409
public void testBinaryStrict() {
410410
List<TestData<BsonBinary>> tests = asList(new TestData<BsonBinary>(new BsonBinary(new byte[0]),
411411
"{ \"$binary\" : \"\", "
412-
+ "\"$type\" : \"0\" }"),
412+
+ "\"$type\" : \"00\" }"),
413413
new TestData<BsonBinary>(new BsonBinary(new byte[]{1}),
414414
"{ \"$binary\" : \"AQ==\", "
415-
+ "\"$type\" : \"0\" }"),
415+
+ "\"$type\" : \"00\" }"),
416416
new TestData<BsonBinary>(new BsonBinary(new byte[]{1, 2}),
417417
"{ \"$binary\" : \"AQI=\", "
418-
+ "\"$type\" : \"0\" }"),
418+
+ "\"$type\" : \"00\" }"),
419419
new TestData<BsonBinary>(new BsonBinary(new byte[]{1, 2, 3}),
420420
"{ \"$binary\" : \"AQID\", "
421-
+ "\"$type\" : \"0\" }"),
421+
+ "\"$type\" : \"00\" }"),
422422
new TestData<BsonBinary>(new BsonBinary((byte) 0x80, new byte[]{1, 2, 3}),
423423
"{ \"$binary\" : \"AQID\", "
424424
+ "\"$type\" : \"80\" }"));

driver-core/src/test/unit/com/mongodb/connection/PlainAuthenticatorUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private void validateMessages() {
6767
String command = MessageHelper.decodeCommandAsJson(sent.get(0));
6868
String expectedCommand = "{ \"saslStart\" : 1, "
6969
+ "\"mechanism\" : \"PLAIN\", "
70-
+ "\"payload\" : { \"$binary\" : \"dXNlcgB1c2VyAHBlbmNpbA==\", \"$type\" : \"0\" } }";
70+
+ "\"payload\" : { \"$binary\" : \"dXNlcgB1c2VyAHBlbmNpbA==\", \"$type\" : \"00\" } }";
7171

7272
assertEquals(expectedCommand, command);
7373
}

driver-core/src/test/unit/com/mongodb/connection/ScramSha1SaslAuthenticatorTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,18 @@ private void validateMessages() {
160160
String expectedFirstCommand = "{ \"saslStart\" : 1, "
161161
+ "\"mechanism\" : \"SCRAM-SHA-1\", "
162162
+ "\"payload\" : { \"$binary\" : \"biwsbj11c2VyLHI9ZnlrbytkMmxiYkZnT05Sdjlxa3hkYXdM\", "
163-
+ "\"$type\" : \"0\" } }";
163+
+ "\"$type\" : \"00\" } }";
164164

165165
String secondCommand = MessageHelper.decodeCommandAsJson(sent.get(1));
166166
String expectedSecondCommand = "{ \"saslContinue\" : 1, "
167167
+ "\"conversationId\" : 1, "
168168
+ "\"payload\" : { \"$binary\" : \"Yz1iaXdzLHI9ZnlrbytkMmxiYkZnT05Sdjlxa3hkYXdMSG8rVmdrN3F2VU9LVXd"
169-
+ "1V0xJV2c0bC85U3JhR01IRUUscD1NQzJUOEJ2Ym1XUmNrRHc4b1dsNUlWZ2h3Q1k9\", \"$type\" : \"0\" } }";
169+
+ "1V0xJV2c0bC85U3JhR01IRUUscD1NQzJUOEJ2Ym1XUmNrRHc4b1dsNUlWZ2h3Q1k9\", \"$type\" : \"00\" } }";
170170

171171
String thirdCommand = MessageHelper.decodeCommandAsJson(sent.get(2));
172172
String expectedThirdCommand = "{ \"saslContinue\" : 1, "
173173
+ "\"conversationId\" : 1, "
174-
+ "\"payload\" : { \"$binary\" : \"dj1VTVdlSTI1SkQxeU5ZWlJNcFo0Vkh2aFo5ZTA9\", \"$type\" : \"0\" } }";
174+
+ "\"payload\" : { \"$binary\" : \"dj1VTVdlSTI1SkQxeU5ZWlJNcFo0Vkh2aFo5ZTA9\", \"$type\" : \"00\" } }";
175175

176176
assertEquals(expectedFirstCommand, firstCommand);
177177
assertEquals(expectedSecondCommand, secondCommand);

0 commit comments

Comments
 (0)