Skip to content

Commit

Permalink
Revert "fix: undefined will stay undefined instead of null"
Browse files Browse the repository at this point in the history
Changing the encoding of `undefined` is a breaking change. 
I am postponing this so we can bundle this with other breaking changes.
It’s still a good idea to change this eventually.

This reverts commit 83af274.
  • Loading branch information
jonasgloning committed Feb 25, 2023
1 parent 275c600 commit da49137
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
5 changes: 5 additions & 0 deletions __test__/bugs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { expect, describe, it } from "@jest/globals";
import { packAndUnpack } from "./util";

describe("Bugs", () => {
describe("Objects", () => {
it("replaces undefined with null ", async () => {
expect(await packAndUnpack(undefined)).toBe(null);
});
});
describe("Numbers", () => {
it("gives back wrong value on INT64_MAX ", async () => {
expect(await packAndUnpack(0x7fffffffffffffff)).toBe(
Expand Down
3 changes: 0 additions & 3 deletions __test__/objects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ describe("Binarypack", () => {
it("should keep null", async () => {
expect(await packAndUnpack(null)).toEqual(null);
});
it("should keep undefined", async () => {
expect(await packAndUnpack(undefined)).toEqual(undefined);
});

it("should transfer Uint8Array views correctly", async () => {
const arr = new Uint8Array(8);
Expand Down
2 changes: 1 addition & 1 deletion lib/binarypack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ export class Packer {
this._bufferBuilder.append(0xc2);
}
} else if (value === undefined) {
this._bufferBuilder.append(0xc1);
this._bufferBuilder.append(0xc0);
} else if (typeof value === "object") {
if (value === null) {
this._bufferBuilder.append(0xc0);
Expand Down

0 comments on commit da49137

Please sign in to comment.