Skip to content

Commit

Permalink
fix: undefined will stay undefined instead of null
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasgloning committed Feb 17, 2023
1 parent 3475f45 commit 83af274
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
5 changes: 0 additions & 5 deletions __test__/bugs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ 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: 3 additions & 0 deletions __test__/objects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ 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 as ArrayBuffer", async () => {
const values = [
Expand Down
2 changes: 1 addition & 1 deletion lib/binarypack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ class Packer {
this.bufferBuilder.append(0xc2);
}
} else if (value === undefined) {
this.bufferBuilder.append(0xc0);
this.bufferBuilder.append(0xc1);
} else if (typeof value === "object") {
if (value === null) {
this.bufferBuilder.append(0xc0);
Expand Down

0 comments on commit 83af274

Please sign in to comment.