Skip to content

Commit e1a7ac1

Browse files
authored
fix(json codec): encode the empty buffer properly (#312)
## Why `{ $t: "" }` means that `$t` is false-y so we dont treat it as the buffer type ## What changed make it a strict undefined check ## Versioning - [ ] Breaking protocol change - [ ] Breaking ts/js API change <!-- Kind reminder to add tests and updated documentation if needed -->
1 parent 51ca05d commit e1a7ac1

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
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;

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@replit/river",
33
"description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!",
4-
"version": "0.208.0",
4+
"version": "0.208.1",
55
"type": "module",
66
"exports": {
77
".": {

0 commit comments

Comments
 (0)