Skip to content

Commit 9d35d25

Browse files
authored
fix(service-provider-core): include padding in packed bits inspect MONGOSH-2153 (#2433)
1 parent ccc966c commit 9d35d25

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

packages/service-provider-core/src/printable-bson.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ describe('BSON printers', function () {
108108
).to.equal('Binary.fromPackedBits(new Uint8Array([ 1, 2, 3 ]))');
109109
});
110110

111+
it('formats PackedBits correctly with padding', function () {
112+
expect(
113+
inspect(bson.Binary.fromPackedBits(new Uint8Array([1, 2, 3]), 7))
114+
).to.equal('Binary.fromPackedBits(new Uint8Array([ 1, 2, 3 ]), 7)');
115+
});
116+
111117
it('formats Float32Array correctly', function () {
112118
expect(
113119
inspect(

packages/service-provider-core/src/printable-bson.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,17 @@ const binaryVectorInspect = function (
5959
maxArrayLength: utilInspect.defaultOptions.maxArrayLength,
6060
})
6161
)}))`;
62-
case BSON.Binary.VECTOR_TYPE.PackedBit:
62+
case BSON.Binary.VECTOR_TYPE.PackedBit: {
63+
const paddingInfo = this.buffer[1] === 0 ? '' : `, ${this.buffer[1]}`;
6364
return `Binary.fromPackedBits(new Uint8Array(${removeTypedArrayPrefixFromInspectResult(
6465
utilInspect(this.toPackedBits(), {
6566
depth,
6667
...options,
6768
// These arrays can be very large, so would prefer to use the default options instead.
6869
maxArrayLength: utilInspect.defaultOptions.maxArrayLength,
6970
})
70-
)}))`;
71+
)})${paddingInfo})`;
72+
}
7173
default:
7274
return binaryInspect.call(this, depth, options);
7375
}

0 commit comments

Comments
 (0)