Skip to content

Commit a099af6

Browse files
committed
oops make sure empty uint8array works
1 parent 51ca05d commit a099af6

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

codec/codec.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ describe.each(codecs)('codec -- $name', ({ codec }) => {
1717
expect(codec.fromBuffer(codec.toBuffer(msg))).toStrictEqual(msg);
1818
});
1919

20+
test('encodes the empty buffer properly', () => {
21+
const msg = { test: new Uint8Array(0) };
22+
expect(codec.fromBuffer(codec.toBuffer(msg))).toStrictEqual(msg);
23+
});
24+
2025
test('skips optional fields', () => {
2126
const msg = { test: undefined };
2227
expect(codec.fromBuffer(codec.toBuffer(msg))).toStrictEqual({});

codec/json.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const NaiveJsonCodec: Codec = {
5151
const parsed = JSON.parse(
5252
decoder.decode(buff),
5353
function reviver(_key, val: unknown) {
54-
if ((val as Base64EncodedValue | undefined)?.$t) {
54+
if ((val as Base64EncodedValue | undefined)?.$t !== undefined) {
5555
return base64ToUint8Array((val as Base64EncodedValue).$t);
5656
} else {
5757
return val;

0 commit comments

Comments
 (0)