Skip to content

Commit

Permalink
Serialize JS booleans
Browse files Browse the repository at this point in the history
  • Loading branch information
bartblast committed Oct 17, 2024
1 parent 525d52f commit 74ff796
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion assets/js/serializer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export default class Serializer {
if (
!serialized.startsWith('"') &&
!serialized.startsWith("{") &&
!serialized.startsWith("[")
!serialized.startsWith("[") &&
!["true", "false"].includes(serialized)
) {
// [version, data]
return `[1,"${serialized}"]`;
Expand Down
16 changes: 16 additions & 0 deletions test/javascript/serializer_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,22 @@ describe("Serializer", () => {
assert.equal(serialize(term), expected);
});
});

describe("boolean", () => {
it("top-level", () => {
const term = true;
const expected = "[1,true]";

assert.equal(serialize(term), expected);
});

it("nested", () => {
const term = {a: true, b: 2};
const expected = '[1,{"a":true,"b":2}]';

assert.equal(serialize(term), expected);
});
});
});
});
});

0 comments on commit 74ff796

Please sign in to comment.